[Rcpp-devel] Exposed C++-Class used within another exposed C++-Class

Paul Theodor Pyl pyl at embl.de
Mon Jun 28 16:48:53 CEST 2010


Hi,

I have a C++Class 'DSV' that I have successfully made accessible from R 
with the following piece of code:

RCPP_MODULE(blubb){

using namespace Rcpp;

typedef DSV< int, int > DSVi;
class_< DSVi >( "DSVi" )
.method( "get", &DSVi::get )
.method( "set", &DSVi::set )
.method( "add", &DSVi::add )
.method( "info", &DSVi::rinfo )
.method( "apply", &aply< int, int > )
;

class_< DSVVec >( "DSVVec" )
.method( "[[", &DSVVec::operator[] )
.method( "load", &DSVVec::load );
}

Now I would like to use another C++-class that will contain a vector of 
DSV's, for example like so:

class DSVVec{

public:

DSVVec() {};

void load( std::string filename ) {
/* ... */
}

DSV< int, int > & operator[]( std::string name ){
return dsvs[ GetID( name ) ];
}

int GetID( std::string n ){ /* ... */ }

private:
std::vector< DSV< int, int > > dsvs;

};

When I try this I get an error message from Rcpp that the generic 
wrapping around DSV< int, int > has failed.
(/wrap.h:395: error: cannot convert ‘const DSV<int, int>’ to ‘SEXPREC*’ 
in initialization)
Now the question is how to get 'DSVVec' to apply my already defined 
wrapper for 'DSV' on the return value of it's operator[] function?

I use Rcpp 0.8.2 as downloaded from CRAN.

Cheers,
Paul


More information about the Rcpp-devel mailing list