【问题标题】:Mixing std::move() and std::thread won't compile混合 std::move() 和 std::thread 不会编译
【发布时间】:2015-04-23 18:11:24
【问题描述】:

代码如下:

#include <memory>
#include <thread>

class A
{
  void foo(int&& arg) const {}

  void boo() const 
  {
    int value(0);
    std::thread t(&A::foo, this, std::move(value));
    t.join();
  }

};

int main()
{
  A a;
  return 0;
}

MS Visual Studio 2012 (toolset v110) 给出下一个错误:

错误 C2664:'_Rx std::_Pmf_wrap<_pmf_t>::operator ()(const _Wrapper &,_V0_t) const':无法转换参数 2 从'int'到'int &&'

那是什么?我们不能通过线程使用移动语义吗?

【问题讨论】:

  • 不管怎样,这确实可以在 g++ 和 clang 中编译。

标签: c++ c++11


【解决方案1】:

这是 VS 中的错误。你可以看到这个:

https://connect.microsoft.com/VisualStudio/feedback/details/737812

// 开业时间:2012 年 4 月 19 日晚上 8:58:36,嗯 :)

以及他们页面中的解决方法:

你可以使用std::ref,但不一样。

已固定关闭,因此您可能需要使用从不工具或使用“解决方法”。

【讨论】:

猜你喜欢
  • 2015-09-12
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
  • 1970-01-01
  • 2021-08-03
  • 1970-01-01
  • 1970-01-01
  • 2016-07-08
相关资源
最近更新 更多