混合 std::move() 和 std::thread 无法编译
Mixing std::move() and std::thread won't compile
具有如下代码:
#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) 给出下一个错误:
错误 C2664:"_Rx std::_Pmf_wrap<_Pmf_t,_Rx,_Farg0,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,>::运算符 ()(常量 _Wrapper &,_V0_t) const' : 无法转换参数 2 从 'int' 到 'int &&&'
什么?我们不能通过线程使用移动语义吗?
这是
VS中的错误。你可以看到这个:
https://connect.microsoft.com/VisualStudio/feedback/details/737812
//打开时间: 4/19/2012 20:58:36, 嗯:)
以及他们页面的解决方法:
您可以使用
std::ref
,但它不一样。
已关闭为固定,因此您可能永远需要使用工具或使用"解决方法"。
相关文章:
- std::is_base_of表示ctor编译错误
- 关于std::move的使用,是否有编译警告
- std::experimental::source_location 在编译时
- C++如果必须在编译时确定大小,std::array 有什么意义?
- std::vector::p ush_back() 不会在 MSVC 上编译具有已删除移动构造函数的对象
- std::cout输出int时出现编译错误
- 在缺少函数重载时抛出异常,并带有 std::variant 而不是编译时错误
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- 确保编译时的特定 std::array 位置
- 编译器不会使用 -std=c++11 编译智能指针
- GCC 8.3 无法编译 std::bind_front
- 使用 std::enable_if 限制派生类的模板参数时出现编译错误
- 使用 CImg 库的 std::min 和 std::max 的编译问题
- std::less是否应该允许在编译时比较不相关的指针?
- 为什么 std::make_shared 无法编译带有已删除运算符 new 的类型?
- std::variant<>::get() 不能使用 Apple LLVM 10.0 编译
- 对带有唯一指针的 std::thread 使用类成员函数时出现编译错误
- QString和stdstring组合在std::编译错误中不起作用
- 使用typedef和std编译错误
- std::编译期间设置的数组类成员