In the following code:
#include <iostream.h>
class Base
{
public:
Base(){ cout<<"Constructor: Base"<<endl;}
~Base(){ cout<<"Destructor : Base"<<endl;}
};
class Derived: public Base
{
//Doing a lot of jobs by extending the functionality
public:
Derived(){ cout<<"Constructor: Derived"<<endl;}
~Derived(){ cout<<"Destructor : Derived"<<endl;}
> };
void main()
{
Base *Var = new Derived();
delete Var;
}
why is constructor of Base is also being called when only the constructor is Derived being called by new? Why is the calling of the constructor of Derived is called? And also why the destructor of Derived is not called at all?