[Rcpp-devel] Invoking class methods via XPtr<> objects in R

Suresh Easwar seaswar at yahoo.com
Wed Mar 13 15:15:22 CET 2013


How does one invoke class methods via XPtr<T> objects in R? I get this error: Error in aptr$f : object of type 'externalptr' is not subsettable:
 
cpp file:
#include <Rcpp.h>
struct A {
void f() {}
};
typedef Rcpp::XPtr<A> APtr;
APtr getAPtr()
{
return APtr(new A);
}
struct B {
B(APtr) { }
};
RCPP_MODULE(mytest)
{
                Rcpp::function("get_aptr", &getAPtr);
                Rcpp::class_<A>("A")
                                .constructor()
                                .method("f", &A::f)
                ;
                Rcpp::class_<B>("B")
                                .constructor<APtr>()
                ;
}
 
R session:
R version 2.15.3 (2013-03-01) -- "Security Blanket"
Copyright (C) 2013 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)
> library(mytest)
Loading required package: Rcpp
> a <- new(A)
> aptr <- get_aptr()
> b <- new(B, aptr)
> a$f()
> aptr$f()       <- not sure how to invoke f() via aptr
Error in aptr$f : object of type 'externalptr' is not subsettable
> 
 
Thanks
 
Suresh


More information about the Rcpp-devel mailing list