Consider the following C ++ code.
struct foo { std::string value; }
inline foo bar() { return { "42" }; }
Now imagine that I have a function that uses bar () as follows.
std::string my_func()
{
const auto &x = bar();
return x.value;
}
Does this memory leak. Since my_func only contains a reference to x? Or is x still cleared after my_func completes?
I know that this does not mean that links should be used. But I just realized that this compiles, and wondered what semantics are.
source
share