For example if I have an object that contains a pointer to a dynamically allocated object, then assign it to another object with the same type, i.e.
object2 = object1;
and the destructor will explicitly delete the dynamically allocated object. So when object2 and object1 go out of scope, an error will occur (which I assume to be because the address for the dynamically allocated object is deleted twice). So what should I do to fix/avoid this problem?