混合std :: move()和std :: thread将无法编译

And*_*mov 5 c++ c++11

代码如下:

#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;
}
Run Code Online (Sandbox Code Playgroud)

MS Visual Studio 2012(工具集v110)给出下一个错误:

错误C2664:'_ Rx std :: _ Pmf_wrap <_Pmf_t,_Rx,_Farg0,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,> :: operator()(const _Wrapper&,_ V0_t)const':无法从'转换参数2' int'到'int &&'

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

sen*_*fen 9

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

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

//已打开:2012年4月19日下午8:58:36,嗯:)

从他们的页面解决方法:

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

关闭为固定,因此您可能需要使用从不使用工具或使用"解决方法".