[Rcpp-devel] Module with out default constructor.

Romain Francois romain at r-enthusiasts.com
Thu Oct 28 03:36:22 CEST 2010


Le 27/10/10 12:32, Andrew Redd a écrit :
> Is it possible with Rcpp Modules to have a class that does not have a
> default constructor?  Consider this example
> -----
> #include <R.h>
> #include <Rcpp.h>
> class c1{
> private:
> int n;
> int * x;
> c1();
> public:
> c1(int n):n(n){}
> int getn(){return n;}
> };
> RCPP_MODULE(c1){
> using namespace Rcpp;
> class_<c1>("c1")
> .property("n",&c1::getn)
> ;
> }
> -----
> Here I have a class that I do not want to allow to initialize without
> specifying n.  Yes it does not do anything but the question is related
> to a class where constructors and destructors allocate and free special
> memory.   And Yes I know that this fails on compile since c1() is
> private. Can Rcpp handle this kind of setup?  If not suggestions about
> workarounds?
>
> thanks,
> Andrew

At the moment, classes that are exposed through Rcpp modules require 
default constructors.

We need to take some inspiration from boost.python again to allow other 
constructors. e.g. 
http://www.boost.org/doc/libs/1_44_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.constructors

This has been on our list for some time now. Not sure when we will have 
this. Additional resources are welcome.

Romain



More information about the Rcpp-devel mailing list