Dear All,
Is there any easy way to make sure all my object copies are deep copy
or shallow copy? I do not like to implement it in each class one by
one.
To make sure that all copies made are deep copies don't use dynamic
memory for the members of the classes. For shallow copy make sure that
you use dynamic memory for the members and overload the copy-constructor
and assignment-operator (don't forget the destructor).
If you want to allow a class to be either deep or shallow you'll have to
do a bit more work, perhaps use templates to parameterize the class and
provide two copy-constructors and assignment-operators, one for deep and
one for shallow.
I don't think there's any generic way that will apply to all classes
since even in a shallow copy there are usually some things that should
be copied deep.