[Rcpp-devel] Overloaded constructors?

Christian Gunning xian at unm.edu
Thu Aug 11 12:48:28 CEST 2011


> 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).

Did you look at the documentation for Rcpp modules, as Dirk hinted at?
 If you can use modules for your needs, look at section 2.2 here
http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-modules.pdf.
 This is more or less what you're looking for, no?

> 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?

The second point above (function pointers to c++ functions) should
make it into the quickref when i have some time.  I posted a bit about
this on the list last week -- i'm thinking about something like a c++
apply() function using rcpp's row/column magic as a super-simple
example.

If you can write up a simple example of the first point, i'd be happy
to copy-edit it into the quickref.

Christian

>
> 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
>
>
>
> ------------------------------
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
>
> End of Rcpp-devel Digest, Vol 22, Issue 16
> ******************************************
>



-- 
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!


More information about the Rcpp-devel mailing list