<div dir="ltr"><div>Hi, Romain,</div><div><br></div><div>I have created overloaded methods have argument types like blow.</div><div><br></div><div>fn(List)</div><div>fn(List, NumericMatrix)</div><div>fn(List, DataFrame)</div>
<div><br></div><div>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". </div>
<div><br></div><div>Then I review your webpage (<a href="http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-November/001326.html">http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-November/001326.html</a>) 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 ?</div>
<div><br></div><div>#include <Rcpp.h></div><div><br></div><div>using namespace Rcpp;<br>using namespace std;</div><div><br></div><div>class Randomizer {<br>public:</div><div> Randomizer(){}</div><div> NumericVector get( int n ){<br>
RNGScope scope ;<br> return runif( n, 0.0, 1.0 );<br> }</div><div> List get( IntegerVector n ){<br> RNGScope scope ;<br> int size = n.size() ;<br>
List res( size) ;<br> for( int i=0; i<size; i++){<br> res[i] = runif(n[i] , 0.0, 1.0 ) ;<br> }<br> return res ;<br> }</div><div>} ;</div>
<div>bool get_int_valid(SEXP* args, int nargs){<br> if( nargs != 1 ) return false ;<br> if( TYPEOF(args[0]) != INTSXP ) return false ;<br> return ( LENGTH(args[0]) == 1 ) ;<br>}</div><div>RCPP_MODULE(mod){</div>
<div> using namespace Rcpp;</div><div> class_<Randomizer>( "Randomizer" )</div><div> .default_constructor()</div><div> .method( "get" , ( NumericVector (Randomizer::*)(int) )(&Randomizer::get) , &get_int_valid ) <br>
.method( "get" , ( List (Randomizer::*)(IntegerVector) )(&Randomizer::get) ) <br> ;</div><div><br>}</div><div><br></div><div>Thanks a lot.</div><div>Chaomei</div></div>