Created
September 25, 2013 06:42
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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