Share
Explore BrainMass

Virtual Functions in Derived Classes that have Non-Virtual Destructors

I am attempting to complete Assignemt Exercise 13.12 in the Deitel&Deitel 5th edition version of C++ How to program. I am running into some early errors in trying to incorporate the Date class into the existing Employee inherited class heirarchy. One issue is that I'm getting erros in the dervied classes that there are virtual functions in derived classes that have non-virtual destructors. I'm not sure what is going on at this point.

Solution Preview

See attached

We need to have virtual destructors for virtual functions.

The order of execution of destructor in an inherited class during a clean up is like this.
1. Derived class destructor
2. Base class destructor

A difference between a destructor (of course also the constructor) and other member functions is that, if a regular member function has a body at the derived class, only the version at Derived class gets executed. Whereas in case of destructor, both derived as well as base class versions get executed.

For example,

#include <iostream.h>
class Base
{
...

Solution Summary

The virtual functions in derived classes that have non-virtual destructors are determined.

$2.19