3

Let's consider the following code:

class Test{
public:
Test method(){
Test t; 
return std::move(t);
}

Test&& methoda2(){
Test t; 
return std::move(t);
}

What is difference between those methods?

Gilgamesz
  • 4,727
  • 3
  • 28
  • 63
  • The second one leads to undefined behaviour because you return a reference to a local variable. The first one works but inhibits copy-elision. `return t;` would be better as this is a move context anyway. – M.M Mar 15 '16 at 22:44

0 Answers0