This first example still yields undefined behaviour, because it has the problem of deleting something twice as, at the start of the CLASS_2 destructor, data and class1->data point at the same thing.Originally Posted by dwks
This example introduces another problem as, within CLASS_2's constructor, class1 is an uninitialised pointer (it is never initialised). So assigning this->data = class1->data yields undefined behaviour.Originally Posted by dwks