Skip to content

Instantly share code, notes, and snippets.

@romainfrancois
Created September 25, 2013 06:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainfrancois/6695921 to your computer and use it in GitHub Desktop.
Save romainfrancois/6695921 to your computer and use it in GitHub Desktop.
Problem exposing inherited member function of derived class to R through RCPP_MODULE
#include <Rcpp.h>
using namespace Rcpp;
class B {
public:
B (SEXP b);
};
template <class T> class A {
public:
double var1;
void fun1();
};
class B_derived : public B {
public:
B_derived(SEXP b);
};
B::B(SEXP b) {};
template <class T> void A<T>::fun1(){
Rcpp::Rcout << "Object of Type= " << DEMANGLE(A) << "\n";
Rcpp::Rcout << "T= " << DEMANGLE(T) << "\n";
}
B_derived::B_derived(SEXP b) : B::B(b) {};
typedef A<B_derived> A_derived ;
RCPP_MODULE(testing) {
class_< A_derived >("A_derived")
.default_constructor()
.field( "var1", &A_derived::var1)
.method("fun1", &A_derived::fun1)
;
}
/*** R
derived <- new( A_derived )
derived$fun1()
*/
> sourceCpp( "mod.cpp" )
> derived <- new(A_derived)
> derived$fun1()
Object of Type= A<B_derived>
T= B_derived
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment