不要将函数的返回值设为&&,

std::string &&get(){
     std::string s = "str";return std::move(s); 
}

代码中返回的字符串s在函数返回时就已经离开作用域调用析构函数,函数的得到的返回值其实是一个野指针。

 

相关文章: