Quick Q: Why do I have to std::move a variable that is already a &&? -- StackOverflow

Today on SO, a frequently asked question and a nicely summed up answer:

std::move on a variable which already is T&&

On the page http://msdn.microsoft.com/en-us/library/dd293665.aspx Microsoft has an example on how to write a move constructor. It is essentially of the form:

MyClass::MyClass(MyClass&& lhs)
{
    *this = std::move(lhs);
}

I have tried and std::move really is required here, but why? I thought the only thing move did was to convert to T&&. But lhs is already of type MyClass&&, is it not?

Add a Comment

Comments are closed.

Comments (1)

0 0

Vladimir Krivopalov said on Jul 30, 2013 10:48 PM:

Isn't it what Andrew Koenig is explaining in this article: http://isocpp.org/blog/2013/07/sometimes-you-must-violate-an-abstraction-to-maintain-it-andrew-koenig ?