小编Mat*_*att的帖子

如果我将一个本地对象移动到一个函数中,它之后是否仍然有效?

所以,这提供了预期的输出:

void f(std::string&& s)
{
   s += " plus extra";
}

int main(void)
{
   std::string str = "A string";
   f( std::move(str) );
   std::cout << str << std::endl;

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

字符串加上额外的

也就是说,当我在Ideone上运行它时,它可以工作,但它是UB吗?在调用之前和之后添加额外的字符串初始化f没有改变任何东西.

c++ move-semantics c++11

16
推荐指数
3
解决办法
887
查看次数

标签 统计

c++ ×1

c++11 ×1

move-semantics ×1