I have the following very simple code that defines a class B that takes as a parameter a pointer to an object of class A.
The code works perfectly if I compile it as standalone C++, but I haven't been able to expose class B using Rcpp. I must be doing something wrong in the line .constructor<A>() near the end. Have tried all the combinations of &, *, etc. and nothing works. I'm lost after many hours of trying. Any ideas are welcome.
#include <Rcpp.h>
using namespace Rcpp;
class A {
public:
A(int val_) { val = val_; }
int val;
};
class B {
public:
B(A& ptr_) { ptr = &ptr_; }
int getval() { return (this->ptr->val); }
A *ptr;
};
RCPP_MODULE(module_cpp) {
using namespace Rcpp;
class_<A>("A")
.constructor<int>()
.field("val", &A::val)
;
class_<B>("B")
.constructor<A>()
;
}