Yes, you have to use std::move()
in the move constructor, like you do. However, your move constructor exactly duplicates the default one. If your class doesn't define any of:
- copy constructor
- copy assignment operator
- move assignment operator
- destructor
then a default move constructor will be generated for you, doing exactly what you did. You're better off leaving out the definition and relying on the default one.
Even if your class defines some of the above, you can ask the compiler to generate the default move constructor:
class Mesh
{
public:
Mesh(Mesh &&) = default;
// the rest as before
};
That way, you don't have to define it and it will work even if you later add other members (without risk of forgetting to add them to the manual move constructor).
Unfortunately, neither of the above applies to Visual Studio 2015 or earlier, which fails to generate default move constructors and doesn't support = default
for move operations. So if you're targetting VS <= 2015, you have to spell out the move constructor by hand—just like you did.