C++ 混合使用std::move()和std::thread赢得';不编译
代码如下:C++ 混合使用std::move()和std::thread赢得';不编译,c++,c++11,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; re
#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;
}
#包括
#包括
甲级
{
void foo(int&&arg)const{}
void boo()常量
{
int值(0);
std::线程t(&A::foo,this,std::move(value));
t、 join();
}
};
int main()
{
A A;
返回0;
}
MS Visual Studio 2012(工具集v110)给出了下一个错误:
错误C2664:“\u Rx”
std::_Pmf_wrap::operator()(const _Wrapper&,_V0_t)const':无法转换参数
2从“int”到“int&”
那是什么?我们不能通过线程使用移动语义吗?这是VS中的错误。您可以看到: // 开放时间:2012年4月19日下午8:58:36,嗯:) 以及他们页面中的解决方法: 您可以使用
std::ref
,但不同
关闭为固定状态,因此可能需要使用never工具或“变通方法” 值得一提的是,它是用g++和clang编译的。谢谢!我花了三年时间才遇到这样的事情,说它在VS 2015 RTM中得到了修复