What does copying an object mean? What are the copy constructor
and the copy assignment operator? When do I need to declare them
myself? How can I prevent my objects from being copied? |show 20
more comments| C++ treats variables of user-defined types with
value semantics. This means that objects are implicitly copied
in various contexts, and we should understand what "copying an
object" actually means. Let us consider a simple example: (If
you are puzzled by the Special member functions What does it
mean to copy a Since we declared neither the copy constructor
nor the assignment operator (nor the destructor) ourselves,
these are implicitly defined for us. Quote from the standard: By
default, copying an object means copying its members: The
implicitly-defined special member functions for Memberwise
copying is exactly what we want in this case: So when should we
declare those special member functions explicitly? When our
class manages a resource, that is, when an object of the class
is responsible for that res