Why exactly are C++ copy constructors
so important?
Copy constructors aren't needed in most other languages because they either:
- Don't have pointers (e.g., old versions of BASIC), in which case copying objects is always safe, or
- Have nothing but pointers/references (e.g., Java, Python), in which case copying is rare, and then can be done with a
copy() or clone() method.
C++ prefers value semantics but also uses a lot of pointers, which means that:
- Objects get copied a lot, and
- You have to specify whether you want a shallow or deep copy, for reasons the others have mentioned.