A
Andy
As I understand it, if you have object1 which has object2 as a member, when
the outer object (object1) is deleted, the destructor of the inner object
(object2) is called BEFORE the destructor of the outer object.
But, while the destructor of object1 is executing, has object2 actually been
freed?
I have seen some code where an outer object contains a smart pointer member.
In the destructor of the outer object a call is made to a method in the
object pointed-to by the smart pointer. I would have thought that by the
time the outer object's destructor is called ALL of its member objects (or
objects pointed-to by smart pointers) would no longer exist, so trying to
call a method like this would cause a memory violation. And yet the program
works OK.
the outer object (object1) is deleted, the destructor of the inner object
(object2) is called BEFORE the destructor of the outer object.
But, while the destructor of object1 is executing, has object2 actually been
freed?
I have seen some code where an outer object contains a smart pointer member.
In the destructor of the outer object a call is made to a method in the
object pointed-to by the smart pointer. I would have thought that by the
time the outer object's destructor is called ALL of its member objects (or
objects pointed-to by smart pointers) would no longer exist, so trying to
call a method like this would cause a memory violation. And yet the program
works OK.