I 've wrote such code applying std::move
to a prvalue from a temporary constructor.
// a std::string instance in class Obj
Obj&& myObj1 = std::move(Obj(1,"lost"));
print(myObj1);
Obj&& myObj2 = Obj(2,"keep");
print(myObj2);
And the print effects is like that (print
also in constructor and destructor):
Construct lost
Destroy lost
obj1:
Construct keep
obj2: keep
Destroy keep
Some questions in stackoverflow say there should be no effect for the first case, I wonder what happens in my code. Is that the Obj(1, "lost")
in the std::move
function as argument and dies when std::move
exit ?