[Rcpp-devel] Initialization through constructor or through assignment?

Douglas Bates bates at stat.wisc.edu
Fri Oct 21 22:12:11 CEST 2011


Perhaps this is an indication that I should read some sections of "C++
Annotations" again.  I am trying to remember the pros and cons of
initializing a class instance in C++ through assignment or through the
copy constructor.  So, for example, if I have a class "foo" and a
function "bar" that returns a foo.  Am I better off writing

foo   baz(bar());

or

foo   baz = bar();

I have tended to prefer the former, but not for any good reasons, at
least as far as I can remember.

As a much more trivial example, in C I would write

int one = 1;

but in C++ I tend to write

int one(1);

Any comments one way or the other?


More information about the Rcpp-devel mailing list