[Rcpp-devel] Constructor for templated Rcpp::Matrix class from Rcpp::Dimension fails

Douglas Bates bates at stat.wisc.edu
Wed Jun 1 21:36:41 CEST 2011

I am developing classes for sparse matrices with an Rcpp interface that includes

	Rcpp::Dimension dim() const {return Rcpp::Dimension(nr(), nc());}

	Rcpp::NumericMatrix     asmatrix() const;

The implementation of the asmatrix method begins with

	Rcpp::NumericMatrix ans(dim());

which is a public constructor for the Rcpp::Matrix template but this
fails stating

In file included from
                 from RcppSparse.h:1,
                 from Module.cpp:1:
In constructor ‘Rcpp::Matrix<RTYPE>::Matrix(const Rcpp::Dimension&)
[with int RTYPE = 14]’:
RcppSparse.h:110:31:   instantiated from here
error: ‘void Rcpp::Vector<RTYPE>::init() [with int RTYPE = 14]’ is
error: within this context
make: *** [Module.o] Error 1

I can program around this problem by generating the
Rcpp::NumericMatrix from the number of rows and number of columns but
I would class the behavior of the constructor mentioned earlier as at
least an "infelicity" (to use Bill Venables' term).

More information about the Rcpp-devel mailing list