I have a function which shall return a char*. Since I have to concatenate some strings, I wrote the following line:
std::string other_text;
// ...
func((\"te
You are allowed to call methods on temporaries, however you have to be careful about object lifetimes -- in particular, if you have a function that returns c_str()
called on a temporary std::string
, that string object will be destroyed when the function returns.
Your code above suffers from this problem.