派生クラスのmovectorを介して、基本クラスのmove ctorを明示的に呼び出そうとしていますが、驚いています。、これは実際には、基本クラスのmovectorではなく基本クラスのcopyctorを呼び出します。
オブジェクトで関数を使用std::move()
して、派生したmovectorが呼び出されていることを確認しています。
コード:
class Base
{
public:
Base(const Base& rhs){ cout << "base copy ctor" << endl; }
Base(Base&& rhs){ cout << "base move ctor" << endl; }
};
class Derived : public Base
{
public:
Derived(Derived&& rhs) : Base(rhs) { cout << "derived move ctor"; }
Derived(const Derived& rhs) : Base(rhs) { cout << "derived copy ctor" << endl; }
};
int main()
{
Derived a;
Derived y = std::move(a); // invoke move ctor
cin.ignore();
return 0;
}
プログラム出力:
ベースコピーコンストラクタ
派生移動コンストラクタ
ご覧のとおり、基本クラスのmove ctorは忘れられているので、どのように呼ぶのですか?