As constructors can be called by name but in case of destrctors it is not true. ..
destructor is called automatically.
#include <iostream>
using namespace::std;
class Base
{
public:
Base(){cout << "Base constructor" << endl;}
virtual ~Base(){cout << "Base destructor" << endl;} virtual void f(){cout << "f in the Base class" << endl;}
void g(){cout << "g in the Base (invoked)" << endl;}
};
class Derived:public Base
{
public:
Derived(){cout << "Derived constructor" << endl;}
~Derived(){cout << "Derived destructor" << endl;}
void f(){cout << "f in the Derived class" << endl;}
void g(){cout << "g in the Derived (invoked)" << endl;}
};
int main()
{
Base *x,*y;
x = new Base;
y = new Derived;
x->f();
y->f();
x->g();
y->g(); delete x;
delete y; return 0;
}