[Rcpp-devel] Initiate NumericMatrix in class constructor from S4 slot

Simon Zehnder szehnder at uni-bonn.de
Wed Mar 6 08:14:04 CET 2013


Dear Rcpp-Devels,

I am a little confused right now with the following setting:

I have a C++ class with for example the following header

#include <RcppArmadillo.h>

class FirstClass {

	public:
		Rcpp::NumericMatrix M;
	
		FirstClass(Rcpp::S4& classS4);
		~FirstClass();
}

Then, in the .cc file I have:

#include <RcppArmadillo.h>
#include "FirstClass.h"

FirstClass::FirstClass(Rcpp::S4& classS4) {

	M(classS4.slot("M_R"));     // array M_R in R
 };

FirstClass::~FirstClass(){};

Now, my compiler always gives me an error: 

error: no match for call to ‘(Rcpp::NumericMatrix {aka Rcpp::Matrix<14>}) (Rcpp::RObject::SlotProxy)’


Do I have to create the Matrix in the constructor differently? I want to reuse memory allocated in R. Further, could the error be triggered by M_R being an array in R? 

Best 

Simon




More information about the Rcpp-devel mailing list