This is probably just newbie silliness to all you c++ gurus but I just
noticed an interesting compiler warning today while compiling this
function:
const std::string& someclass::somemethod()
{
return "This is a string literal";
}
The compiler warned me that an address of a local variable or a
temporary value is being returned.
Does this make sense? Arent string literals basically static chunks of
memory in the data segment?
Why would this be created on the stack?
Or whats going on here and how can I be sure the string is always
available to the caller of the method?
Its no big drama, I am sure I could fix it, but I am just trying to
understand the language etc and how it all works behind the scenes.
Thanks a lot
Kurt