More on the Copy Constructor
Let us look back at the situation. The core of the problems discussed in the previous section is copying an object whose data members are pointers to heap memory.
Each object instance is supposed to point to the area of memory that is allocated specifically for it. For example, class String has a pointer that points to the area of heap memory that contains characters associated with the individual String object.
When data members of one object are copied into data members of another object, the corresponding pointers in both objects will have the same contents. Hence, they will point to the same area of heap memory. These objects can die at different moments in time; for example, the formal value parameter of a function ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access