//Example showing the need for Virtual Destructor

| |


#include <iostream.h>
class Base
{
public:
Base() {
cout<<"Base Constructor Called"<<endl;
}
~Base() {
cout<<"Base Destructor Called"<<endl;
}
};

class Derived : public Base
{
public:
Derived() {
cout<<"Derived Constructor Called"<<endl;
}
~Derived() {
cout<<"Derived Destructor Called"<<endl;
}
};

int main()
{
cout<<"\nTESTING NON-VIRTUAL BASE DESTRUCTOR\n";
Base *b = new (Derived);
delete(b);
return 0;
}
<