When you have a derived object with a move constructor, and the base object also has move semantics, what is the proper way to call the base object move constructor from the derived object move constructor?
I tried the most obvious thing first:
Derived(Derived&& rval) : Base(rval)
{ }
However, this seems to end up calling the Base object's copy constructor. Then I tried explicitly using std::move
here, like this:
Derived(Derived&& rval) : Base(std::move(rval))
{ }
This worked, but I'm confused why it's necessary. I thought std::move
merely returns an rvalue reference. But since in this example rval
is already an rvalue reference, the call to std::move
should be superfluous. But if I don't use std::move
here, it just calls the copy constructor. So why is the call to std::move
necessary?