Program using virtual function causing defined behaviour.

#include
#include

class base
{
public:
base()
{
cout<<"Constructing base n";
}
virtual ~base()
{
cout<<"Destructing base n";
}
};

class derived: public base
{
public:
derived()
{
cout<<"Constructing derived n";
}
~derived()
{
cout<<"Destructing derived n";
}
};
void main()
{
clrscr();
derived *d = new derived();
base *b = d;
delete b;
getch();
}

Leave a reply