我不明白复制顺序如何在类层次结构中工作
这段代码:
class Base
{
protected:
void myBaseMethod()
{
cout << "basemethod";
}
Base() { cout << "default constructor - base"; }
~Base() { }
Base(Base& other)
{
cout << "copy constructor - base";
}
Base& operator= (Base const &)
{
cout << "assignment operator - base";
}
};
class Derived : private Base
{
public:
Derived()
{
cout << "default constructor - derived";
}
};
int main()
{
Derived eaObj;
Derived efu = eaObj;
return 0;
}
按预期输出“默认构造函数 - 基”“默认构造函数 - 派生”,然后输出“复制构造函数 - 基”。
复制对象时调用了哪些复制构造函数?首先是基类,然后是派生类?如果它们是虚拟的呢?