I am trying to call the base class move ctor explicitly through the derived class move ctor, but unexpectedly! which actually calls the copy of the ctor base class NOT the base class move ctor.
I use the std::move() function for an object to make sure that the derived ctor move is called!
The code:
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);
SOFTWARE OUTPUT:
base copy ctor
derivative displacement ctor
As you can see, the base class move ctor is forgotten, as I call it?
source share