#include<iostream>
using namespace std;
class Parent
{
public:
Parent ( )
{
cout << "P";
}
};
class Child : public Parent
{
public:
Child ( )
{
cout << "C";
}
};
int main ( )
{
Child obj1;
Child obj2 ( obj1 );
return 0;
}
Here's what happens in this program:
=> An object of the class 'Child' named 'obj1' is created
=> Call to the constructor of the 'Child' class is made
=> Call to the constructor of the 'Parent' class is made
=> "P" is printed
=> Control transferred back to 'Child ( )'
=> "C" is printed
=> An object 'obj2' of the class 'Child' is created as a copy of 'obj1'
=> Call to the copy constructor of the 'Child' class is made
=> Call to the copy constructor of the 'Parent' class is made
What next? Where is the copy taking place - Parent's copy constructor of Child's? Where all does the control travel before coming back to main ( )?