#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;
}
这是该程序中发生的情况:
=> 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
接下来是什么?复制发生在哪里 - Child 的 Parent 的复制构造函数?在返回 main ( ) 之前,所有控件都在哪里运行?