有代碼如下:混合的std ::移動()和std ::線程不會編譯
#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(工具箱V110)給出了一個錯誤:
error 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' : cannot convert parameter 2 from 'int' to 'int &&'
那是什麼?我們不能通過線程使用移動語義嗎?
對於它的價值,它可以在g ++和clang中進行編譯。 – user2079303