
// Problem without virtual destructors
#include<iostream.h>
#include<conio.h>
class base
{
     public:
          base()
          {
               cout<<"\n Base class constructor";
               cout<<endl;
          }
          ~base()
          {
               cout<<"\n Base class destructor";
               cout<<endl;
          }
};
class derived:public base
{
     public:
          derived()
          {
               cout<<"\n Derived class constructor";
               cout<<endl;
          }
          ~derived()
          {
               cout<<"\n Derived class destructor";
          }
};
void main()
{
     clrscr();
     base *ptr=new derived;
     delete ptr;
}
Test data
Output
Base class constructor
Derived class constructor
Base class destructor