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

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

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

 

相关文章:

  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-01-21
  • 2022-12-23
猜你喜欢
  • 2021-04-03
  • 2022-02-22
  • 2021-05-14
  • 2021-07-23
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案