cppaddict wrote:
It depends on the internals of your class if this is a deep copy
or not.
Thanks for your reply.
What does ithe deepness of the copy depend on? Eg, if one of the
members of my class is a vector which contains other custom objects,
will a deep copy of the vector be made?
Yes.
As a simple rule of thumb.
If you don't need to do any special action in the destructor
to handle a specific member variable, then the copy constructor
and the assignment operator generated by the compiler will do
the right thing.
To your question: Assume there is a std::vector in your
class. You don't need to do anything in the destructor
to free that vector, because the vector handles
everything by itself. But so does it handle everythign
for itself when it is assigned to another vector.
When the compiler generates the code for op=, it uses
memberwise assignment to do this. This means that it
will tell the vector to assign itself to another vector
and since a vector knows how to do this, everything
is correct.
PS)
The above is called: rule of three
Whenever you need one of
* destructor
* copy constructor
* assignment operator
you most likely need all 3 of them
--
Karl Heinz Buchegger
kb******@gascad.at