In C++ what is the best way to return a function local std::string variable from the function?
std::string MyFunc()
{
std::string mystring("test");
return mystring;
}
std::string ret = MyFunc(); // ret has no value because mystring has already gone out of scope...???
No. That is not true. Even if mystring
has gone out of scope and is destroyed, ret
has a copy of mystring as the function MyFunc
returns by value.