Hi, Romain, I have created overloaded methods have argument types like blow.
fn(List) fn(List, NumericMatrix) fn(List, DataFrame) The first function works fine, and adding the second one with different number of arguments works fine too. With the third one added, it compiled fine but when I invoked the third function I got the error message : "Error: not compatible with requested type". Then I review your webpage ( http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-November/001326.html) about the overloaded methods in modules, I tested the following code, but I got a huge of errors output when I compiled it. Not only compilation failure, also I do not quite understand this example using dispatch. Do you think it is possible to achieve the goal of overloaded methods described above using Rcpp ? #include <Rcpp.h> using namespace Rcpp; using namespace std; 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){ using namespace Rcpp; class_<Randomizer>( "Randomizer" ) .default_constructor() .method( "get" , ( NumericVector (Randomizer::*)(int) )(&Randomizer::get) , &get_int_valid ) .method( "get" , ( List (Randomizer::*)(IntegerVector) )(&Randomizer::get) ) ; } Thanks a lot. Chaomei
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel