If I try to return a string literal from a function, I can make these two versions:
std::string get_val()
{
return "1234";
}
const std::string & get_ref()
{
return "1234";
}
However, what confuses me is that I thought you need to have a long-lived object, in order to have an lvalue reference (I am reading const std::string &
as an lvalue reference, perhaps I am mistaken).
Why does this work? Where does "1234"
live after I return from the function?