Does a copy constructor/operator/function need to make clear which copy variant it implements?

Viewed 2307

Yesterday I asked a question about copying objects in C#, and most answers focussed on the difference between deep copy and shallow copy, and the fact that it should be made clear which of both copy variants a given copy constructor (or operator, or function) implements. I find this odd.

I wrote a lot of software in C++, a language that heavily relies on copying, and I never ever needed multiple copy variants. The only kind of copy operation I ever used is the one I call "deep enough copy". It does the following:

  • In case the object has ownership over the member variable (cf. composition), it is copied recursively.
  • In case the object has no ownership over the member variable (cf. aggregation), only the link is copied.

Now, my question is threefold:

4 Answers
Related