1.

Write About The Use Of The Virtual Destructor?

Answer»

When an object is declared with the new operator and the pointer type is that of a base class with a non-virtual destructor, the base destructor executes instead of the derived destructor. When a base class destructor is virtual, the compiler calls the correct destructor function irrespective of the type of the pointer.
If the base class needs no custom destruction, you must still provide a virtual destructor (with an empty BLOCK) to permit the PROPER destructor calls for dynamically allocated objects. Moreover, by making the destructor of the base class as virtual, you can INVOKE the DESTRUCTORS of both the base and derived classes in the reverse order.

When an object is declared with the new operator and the pointer type is that of a base class with a non-virtual destructor, the base destructor executes instead of the derived destructor. When a base class destructor is virtual, the compiler calls the correct destructor function irrespective of the type of the pointer.
If the base class needs no custom destruction, you must still provide a virtual destructor (with an empty block) to permit the proper destructor calls for dynamically allocated objects. Moreover, by making the destructor of the base class as virtual, you can invoke the destructors of both the base and derived classes in the reverse order.



Discussion

No Comment Found