class Base
{
public:
int i;
Base()
{
cout<<"Base Constructor"<<endl;
}
Base (Base& b)
{
cout<<"Base Copy Constructor"<<endl;
i = b.i;
}
~Base()
{
cout<<"Base Destructor"<<endl;
}
void val()
{
cout<<"i: "<< i<<endl;
}
};
class Derived: public Base
{
public:
int i;
Derived()
{
Base::i = 5;
cout<<"Derived Constructor"<<endl;
}
/*Derived (Derived& d)
{
cout<<"Derived copy Constructor"<<endl;
i = d.i;
}*/
~Derived()
{
cout<<"Derived Destructor"<<endl;
}
void val()
{
cout<<"i: "<< i<<endl;
Base::val();
}
};
If i do Derived d1; Derived d2 = d1; The copy constructor of base is called and default copy constructor of derived is called.
But if i remove the comments from derived's copy constructor the base copy constructor is not called. Is there any specific reason for this? Thanks in advance.