best way to return an std::string that local to a function

前端 未结 6 773
陌清茗
陌清茗 2021-01-30 16:07

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\");
    ret         


        
6条回答
  •  天涯浪人
    2021-01-30 16:40

    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.

提交回复
热议问题