Suppose i have a base class "person". and i publically inherits a class "student " from the base class "person". i have not written the copy constructor for base and the derived class. now suppose i write in the main program
main()
{
student sobj1("name", "computer science");
student sobj2=sobj1;
}
now in the second line the default compiler generated copy constructor of the student will be called but before the execution the default copy constructor of the base class will be called which creates an anonymous object and initialize it then control comes back to the copy constructor of the student which initialize the student's portion of the object.
this is the demonstration for the situation where we don't write the copy constructor
now suppose we write the copy constructor for both the classes , then i have tested that when i write
student sobj2=sobj1;
what happens is , this line calles the copy constructor of the student which works , but the copy constructor of the bases class will not be called in this case(default constructor of the base class will be called) my question is why?