You need to make the destructor virtual when an object of a derived class is declared with the new operator and that the pointer type is that of a base class with a non-virtual destructor. When the program destroys the object by using the delete operator with the pointer as an argument, the base destructor executes instead of the derived destructor.
If the base class needs no custom destruction, you must still provide a virtual destructor (with an empty statement block) to permit the appropriate call for the destructor in relation to the dynamically allocated objects. All the classes in the personnel class hierarchy have virtual destructors.
No comments:
Post a Comment