2

クラス階層内でのコピー順序の仕組みがわかりません

このコード:

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;
}

期待どおりに「デフォルト コンストラクター - ベース」「デフォルト コンストラクター - 派生」を出力し、「コピー コンストラクター - ベース」を出力します。

オブジェクトをコピーするときに呼び出されるコピー コンストラクターはどれですか? 最初に基本クラスのもの、次に派生クラスのものですか? それらが仮想の場合はどうなりますか?

4

2 に答える 2