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
Named R-value references are treated as L-value.
So we need std::move
to convert it to R-Value.
You really should use std::forward(obj) rather than std::move(obj). Forward will return the proper rvalue or lvalue based on the what obj is whereas move will turn an lvalue into an rvalue.
rval
is not a Rvalue. It is an Lvalue inside the body of the move constructor. That's why we have to explicitly invoke std::move
.
Refer this. The important note is
Note above that the argument x is treated as an lvalue internal to the move functions, even though it is declared as an rvalue reference parameter. That's why it is necessary to say move(x) instead of just x when passing down to the base class. This is a key safety feature of move semantics designed to prevent accidently moving twice from some named variable. All moves occur only from rvalues, or with an explicit cast to rvalue such as using std::move. If you have a name for the variable, it is an lvalue.