Hi;
I have a short question about pointer and derived inheritance
I have a class Base and a class Derived; they have constructor and destructor.
in main I create it
Base *p=new Derived();
but the output is
Base Constructor
Derived Constructor
Base Destructor
.......................... where is Derived Destructor ? why It is not called ?
Code:
#include<iostream>
using namespace std;
class Base
{
public:
Base() {cout<<"Base Constructor"<<endl;}
~Base() {cout<<"Base Destructor"<<endl;}
};
class Derived: public Base
{
public:
Derived() {cout<<"Derived Constructor"<<endl;}
~Derived() {cout<<"Derived Destructor"<<endl;}
};
int main()
{
Base *p=new Derived();
delete p;
return 0;
}