[Cs3] virtual destructors

Mikhail Nesterenko mikhail at cs.kent.edu
Tue Feb 11 19:36:13 EST 2014


Mikhail Nesterenko wrote:
> 
> Now, the question is which destructor is to be invoked at
> deallocation? If destructor is virtual, then even though the pointer
> "myBread" is of base class, through run-time binding, the destructor
> of the derived class (concrete product) would be invoked. This
> destructor would properly deallocate the object of the derived class
> (pizza).

It was also pointed out to me that the destructor of the derived class
does not override the (virtual) destructor of the base class. As the
(derived) object is deallocated, the destructors are automatically
invoked in the reverse order of object construction: derived
destructor first.




More information about the cs3 mailing list