[Rcpp-devel] Overloaded constructors?

Sebastian Weber sebastian.weber at frias.uni-freiburg.de
Mon Aug 8 12:45:58 CEST 2011


Hi!

Well, I am not that familiar with details of how Rcpp has to work things out, but the job its doing is really great (I would never be able to extend R with C++ code without Rcpp). The situation I am dealing with is something like this:

class A {
public:
A(int argument) {}
A(std::string name) {}
};

Now, given such a class - is there a way to distinguish the two constructors? The way I understand the code in the Rcpp module is to allow for different constructors with different numbers of arguments, but overloaded constructors like the above case are out of scope at the moment. Maybe I have to live with it, but I think there should be a solution to it (i.e. employing singleton factories of the objects). 

The case for methods is greatly solved for example by function pointers to class members or even to function pointers to c++ functions taking as first argument a pointer to the class. BTW, I discovered this very cool feature by reading the code, but there is no documentation yet, right? Does the feature stay in Rcpp?

Cheers,

Sebastian

Am 05.08.2011 um 18:54 schrieb Dirk Eddelbuettel:

> 
> On 5 August 2011 at 12:06, Sebastian Weber wrote:
> | Hi!
> | 
> | I recently learned how to deal with overlaoded functions when I wanna wrap
> | a class function interface with overladed things. The solution is to use
> | function pointers. 
> 
> Or 'factories' with a base class derived classes, and and and. I think there
> are many ways.
> 
> | Now, what comes to the rescue in the case of overladed constructors? Any suggestion?
> 
> What exactly do you want?
> 
> I think the basic word is that at a basic level we just can't.  The R API is
> after C-based and we have to play some tricks about generated names for
> functions etc.  Romain put some tricks into Rcpp modules to allow something
> close to multiple constructors for a Modules object but we can't give you
> each and every feature of C++ in Rcpp as there are some restrictions imposed
> by being in between R and C++ --- which is the space we chose to be in.
> 
> Cheers, Dirk
> 
> -- 
> Gauss once played himself in a zero-sum game and won $50.
>                      -- #11 at http://www.gaussfacts.com

-- 
Sebastian Weber
Group of Cell Communication and Control
Freiburg Institute for Advanced Studies - FRIAS
School of Life Sciences - LIFENET
Albert-Ludwigs-Universität Freiburg
Albertstr. 19
79104 Freiburg
T.: +49-761-203-97237
Fax:+49-761-203-97334



More information about the Rcpp-devel mailing list