samedi 5 août 2017

Why do we need std::move in constructor's initialisation list?

Hi I am reading through Scott Meyer's Effective Modern C++ and in its item 25 it has this example:

class Widget {
    public:
    Widget(Widget&& rhs)
    : name (std::move(rhs.name)),
      p(std::move(rhs.p)
    { ... }
    ...
}

My question here is why do we need the std::move for rhs.name? As rhs is already a rvalue, doesn't that imply rhs.name is also a rvalue so we can safely move it?

Aucun commentaire:

Enregistrer un commentaire