Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualKing Mir

Posted 22 March 2013 - 03:01 PM

SiCrane is right to point out that you need to use std::move inside DoSomething.

The only time an lvalue reference binds an rvalue reference, is in when it's a deduced type, such as a template dependant type, an auto type, or an argument to decltype. Using declarations may also qualify. In these case the rvalue reference behaves as a universal reference, used for perfect forwarding. Whenever an lvalue is passed to such a type, the deduced type is an lvalue reference. In all other cases, the code will not compile.

Also note, the only reason strA cannot be used after it's moved, is because the library part of the standard says so. std::move does not by itself cause that. You could write a class which is safe to move then use.

#2King Mir

Posted 22 March 2013 - 02:56 PM

SiCrane is right to point out that you need to use std::move inside DoSomething.

The only time an lvalue reference binds an rvalue reference, is in when it's a deduced type, such as a template dependant type, an auto type, or an argument to decltype. Using declarations may also qualify. In these case the rvalue reference behaves as a universal reference, used for perfect forwarding. Whenever an lvalue is passed to such a type, the deduced type is an lvalue reference. In all other cases, the code will not compile.

#1King Mir

Posted 22 March 2013 - 02:55 PM

SiCrane is right to point out that you need to use std::move inside DoSomething.

The only time an lvalue reference binds an rvalue reference, is in when it's a deduced type, such as a template dependant type, an auto type, or an argument to decltype. Using declarations may also qualify. In these case the rvalue reference behaves as a universal reference, used for perfect forwarding. Whenever an lvalue is passed to such a type, the deduced type is an lvalue reference.

PARTNERS