Re: memberwise copy
On Mar 17, 4:02 am, "Ivan Novick" <ivan.d.nov...@gmail.com> wrote:
I am wondering what exactly is meant by the term "memberwise copy".
If you don't declare your own copy constructor the implicit copy
constructor should do memberwise copy of its subojects. So does this
mean that the subobjects are copied with the assignment operator, copy
constructor, or it's just a bit copy of the actual data?
Formally, one can consider that every object has a copy
constructor; the compiler generated copy constructor invokes the
copy constructor for each sub-object (and the compiler generated
copy assignment operator invokes the copy assignment operator
for each sub-object... possibly more than once if virtual
inheritance is involved).
Formally, the standard never considers the possibility of a
bitwise copy, but practically, it defines the concept of a
"trivial" copy constructor to correspond to one where bitwise
copy would work.
In this program the assignment operator is not printed, but I would
have expected it to be printed if memberwise copy is done via
assignment operators.
What am I missing here?
The fact that you never invoke an assignment operator.
Assignment and construction are two very different things.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]