You take a link to a temporary object. The only legal way to do this is:
const object& ( l),
object&& ( r-)
() .
:
, . , , :
{
const string& s = foo();
cout << s << endl;
}
, , , :
{
string s& = foo();
s += "bar";
}
, , , , :
string foo();
void bar(string& s);
bar(foo());
:
string s = foo();
s += "bar";
, (l-value).
r-value , move move-assign. , . , .
, :
string&& s = foo();
s += "bar";
baz(std::move(s));
, && , , .
, , , :
string foo();
void bar(string&& s);
bar(foo());
string s = foo();
bar(move(s));
++ 11, :
void bar(string s);
const string& s = foo();
bar(s);
void bar(const string& s);
const string& s = foo();
bar(s);