Remix.run Logo
HarHarVeryFunny 11 hours ago

How is the compiler meant to guess the semantics of your pointer or reference members?

If they are referring to static or external variables, then presumably the default member-wise "shallow" copy is what you want.

If your pointer is instead referring to some allocated storage, then presumably you do NOT want to just copy the pointer, but the language is not a mind reader - it doesn't know what your pointer means, and it supports copy constructors precisely so that you can implement whatever is needed. The language is giving you the tools to define how you want your pointer to be "copied"... it's your choice whether an exact "shallow" copy is appropriate, or whether you need to do something else.

This is one of many reasons why if you are trying to write modern C++ you should use C++ alternatives to C ones wherever they exist - use STL containers rather than writing your own, use smart pointers rather than raw ones, etc.