[Rcpp-devel] Fwd: Compilation errors on overloaded methods in modules - one with dispatch based on the arguments

Chaomei Lo chaomeilo at gmail.com
Wed Aug 27 19:05:15 CEST 2014


Dear all, I have posted this few days ago, can anybody helps me with this
compilation error ?  I think I understand the valid method, but 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.

Thanks a bunch !


#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) )
                ;

}


---------- Forwarded message ----------
From: Chaomei Lo <chaomeilo at gmail.com>
Date: Sat, Aug 23, 2014 at 12:51 PM
Subject: Compilation errors on overloaded methods in modules - one with
dispatch based on the arguments
To: "rcpp-devel at lists.r-forge.r-project.org" <
rcpp-devel at lists.r-forge.r-project.org>


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140827/6564cfe5/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: overloaded_error.docx
Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Size: 14216 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140827/6564cfe5/attachment-0001.docx>


More information about the Rcpp-devel mailing list