B
blangela
What does the default assignment operator (compiler supplied assignment
operator, sometimes also referred to as the implicit assignment
operator or the synthesized assignment operator) do when the class
contains a reference. For example if the iref member of object A
references X and the iref member of B references Y, if we then go:
A = B;
will the iref member of A now reference X or Y.
If yes, then by my understanding of the term "shallow copy", a shallow
copy has occurred.
If instead, the iref member of A still references X and in fact Y's
value has been assigned to X, then by my understanding of the term, a
"deep copy" has occurred.
If the compiler does simple bitwise copy, then I would guess the
shallow copy is performed. If the complier actually does a memberwise
assignment of each member of the class, then a deep copy is likely
performed.
Also, can I assume that whatever the answer is for above, will be the
same for the compiler supplied copy constructor. For example:
MyClass A(B); // invokes default copy ctor
I realize this would be easy to confirm with some simple code, but I
don't have access to a C++ compiler at the moment.
Cheers,
Bob L.
operator, sometimes also referred to as the implicit assignment
operator or the synthesized assignment operator) do when the class
contains a reference. For example if the iref member of object A
references X and the iref member of B references Y, if we then go:
A = B;
will the iref member of A now reference X or Y.
If yes, then by my understanding of the term "shallow copy", a shallow
copy has occurred.
If instead, the iref member of A still references X and in fact Y's
value has been assigned to X, then by my understanding of the term, a
"deep copy" has occurred.
If the compiler does simple bitwise copy, then I would guess the
shallow copy is performed. If the complier actually does a memberwise
assignment of each member of the class, then a deep copy is likely
performed.
Also, can I assume that whatever the answer is for above, will be the
same for the compiler supplied copy constructor. For example:
MyClass A(B); // invokes default copy ctor
I realize this would be easy to confirm with some simple code, but I
don't have access to a C++ compiler at the moment.
Cheers,
Bob L.