Copy Constructor Question

Why do you have to provide your own copy constructor and assignment operator for classes with fields dynamically allocated memory?

Answer:


To prevent ptr aliasing, and when one class is destroyed, the ptr belonging to another can be distroyed., or use auto_ptr.

No comments: