[Rcpp-devel] Picking off a matrix-valued list element inside a class constructor?

Darren Cook darren at dcook.org
Tue Oct 25 02:35:58 CEST 2011


>> i would advise using this as the ctor of CCC :
>>  
>>  CCC(Rcpp::List l) : m( l["m"] ) {}
> 
> Thanks, Romain.  Pardon my ignorance, but did you mean that I should use that
> declaration literally, or was it merely intended to suggest the approach?

This is the preferred way in C++ to initialize data members. (For
efficiency; see Effective C++ item 12 for more on this.)

(Here you're effectively just copying an integer, so the efficiency gain
is practically unmeasurable; use whichever style you feel most
comfortable with.)

> I tried using it literally and still got a compilation error.

I did too. I'm hoping Romain will take another look at it; I'm wondering
if there is a template specialization (or sumfin' like that) missing?
(E.g. there might be a copy constructor specialization, but not the
corresponding operator=() one ?)

Darren


More information about the Rcpp-devel mailing list