[Rcpp-devel] Fwd: overloaded methods

Chaomei Lo chaomeilo at gmail.com
Thu Aug 28 23:54:05 CEST 2014


Not expect to fix the problem this easy. I just get a chance to look into
the "Module_generated_method.h" code and Romain left a "const char
*" before the valid method. So here below is the fix.

RCPP_MODULE(mod){
        using namespace Rcpp;
        class_<Randomizer>( "Randomizer" )
            .default_constructor()
                .method( "get" , ( NumericVector (Randomizer::*)(int)
)(&Randomizer::get) , "Randomizer", &get_int_valid)
                .method( "get" , ( List (Randomizer::*)(IntegerVector)
)(&Randomizer::get) )
                ;
}

Thanks.

---------- Forwarded message ----------
From: Chaomei Lo <chaomeilo at gmail.com>
Date: Wed, Aug 27, 2014 at 10:17 AM
Subject: overloaded methods
To: "rcpp-devel at lists.r-forge.r-project.org" <
rcpp-devel at lists.r-forge.r-project.org>


Sorry to bug you all, I accidently sent a wrong message few minutes ago.

I have posted this problem few days ago, can anybody helps me with this
compilation error ? I do not have idea why there is no matching function...
It is from Romain's example -
http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-November/001326.html.
I have attached the output of the compiling errors.

////////////////////////////////////////////////////////
class Randomizer {
public:

     Randomizer(){}

NumericVector get( int n ){
RNGScope scope ;
return runif( n, 0.0, 1.0 );
}

List get( IntegerVector n ){
RNGScope scope ;
int size = n.size() ;
List res( size) ;
for( int i=0; i<size; i++){
    res[i] = runif(n[i] , 0.0, 1.0 ) ;
}
return res ;
}

} ;

bool get_int_valid(SEXP* args, int nargs){
     if( nargs != 1 ) return false ;
     if( TYPEOF(args[0]) != INTSXP ) return false ;
     return ( LENGTH(args[0]) == 1 ) ;
}

RCPP_MODULE(mod){

class_<Randomizer>( "Randomizer" )

    .default_constructor()

.method( "get" , ( NumericVector (Randomizer::*)(int) )(
&Randomizer::get) , &get_int_valid )
.method( "get" , ( List (Randomizer::*)(IntegerVector) )(
&Randomizer::get) )
;


}

Thanks a bunch !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140828/dfffdbb7/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: overloaded.docx
Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Size: 14218 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140828/dfffdbb7/attachment-0001.docx>


More information about the Rcpp-devel mailing list