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

Romain Francois romain at r-enthusiasts.com
Mon Jul 5 10:26:26 CEST 2010


Hi,

Nice to see that people are experimenting with modules.

Le 28/06/10 16:48, Paul Theodor Pyl a écrit :
>
> 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?

You typically see errors like "cannot convert ... to ‘SEXPREC*’" when 
the classes are declared too late.

This is something we try to address in the Rcpp-modules vignette. 
Essentially, it should work if you declare your class between including 
RcppCommon.h and Rcpp.h

#include <RcppCommon.h>
// declare (not necessarily define) DSV, etc ..
#include <Rcpp.h>

If you post a dummy version of your classes, I will have a look.


> I use Rcpp 0.8.2 as downloaded from CRAN.
>
> Cheers,
> Paul
> _______________________________________________
> 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
>
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/98Uf7u : Rcpp 0.8.1
|- http://bit.ly/c6YnCi : graph gallery collage
`- http://bit.ly/bZ7ltC : inline 0.3.5



More information about the Rcpp-devel mailing list