Suppose I have a base class "man." and I publicly inherit the student class from the human base class. I did not write a copy constructor for the base and derived class. Now suppose I write in the main program
main()
{
student sobj1("name", "computer science");
student sobj2=sobj1;
}
Now the second compiler of the student instance will be called in the second line, but before execution, the default copy constructor of the base class will be called, which creates an anonymous object and initializes it, then control returns to the copy of the student constructor, which initializes the student part of the object.
this is a demonstration of the situation where we are not writing a copy constructor
now suppose we are writing a copy constructor for both classes, then I checked that when I write
student sobj2=sobj1;
what happens, this line calls the copy constructor of the student that works, but the copy constructor of the base class will not be called in this case (by default the default constructor for the base class will be created), why my question?