VisionSet said:
Is there any kind of convention that dictates where it is usual to perform
shallow and deep copies?
I'd say you perform deep copies only where necessary, and shallow copies
everywhere else. The trick is to determine the meaning of "necessary"
for your application, and that may not be straightforward.
I prefer to use copy constructors to implement any kind of copy, but now I
find the need for a shallow and deep copy in the same class.
That may well be, but I am inclined to suspect that the need could be
removed by a round of refactoring. I would be nervous at the prospect
of putting both behaviors on the same class because there is then great
opportunity for users to accidentally confuse them.
I haven't ever needed to implement copy(), I imagine that its purpose is for
RTTI.
You mean "clone()", you wrote elsewhere. In that context then, do you
mean you think the purpose is to _avoid_ the need for RTTI? In that I
would partially agree with you -- only partially, because you still have
to worry about whether the objects in question are Cloneable. Also, if
you plan for such a feature in your own classes then you can usually
implement it in a polymorphic way without using clone.
John Bollinger
(e-mail address removed)