std::线程类方法错误
std::thread class method errors
我正试图创建线程,以便在基于网格的地形上逐行运行(我不是在问这是否有效,我只是在测试一些东西),但我一直遇到两个错误:
首先,如果我不通过的功能
&DJM::Terrain:GenBlocks
编译器告诉我附加&一开始,但当我使用引用时,它会给我一个连接到xmemory 的单独错误
error C2248: 'std::thread::thread' : cannot access private member declared in class 'std::thread'
1> d:program filesvisual studio 2012vcincludethread(73) : see declaration of 'std::thread::thread'
1> d:program filesvisual studio 2012vcincludethread(32) : see declaration of 'std::thread'
我真的不明白为什么。我在很多地方读到,你应该把this作为第二个参数,但这给出了与上面完全相同的错误。我也尝试过将I作为std::ref传递,但这会产生同样的错误。
for(size_t i = 0; i < mHEIGHT; ++i){
std::thread t(&DJM::Terrain::GenBlocks, &i);
mThreads.push_back(t);
}
for(std::vector<std::thread>::iterator iter = mThreads.begin(); iter != mThreads.end(); iter++){
iter->join();
}
相当大的代码文件,所以我不想发布整个类,但如果我发布的代码没有立即出现错误,我很乐意发布其余的代码。请注意,mThreads存储为一个成员变量。
std::thread
s无法复制。将其移动到矢量中:
mThreads.push_back(std::move(t));
相关文章:
- 我的模板类方法返回错误类型?
- 派生类调用父类的方法,该方法调用重写的虚拟方法调用错误的方法
- 类方法 - 数据结构中 For 循环的运行时错误
- 从 ObjC 代码调用 .mm 类方法时编译错误
- 接受 lambda 作为参数的类方法 - 错误消息
- 如何在尝试为某些非类型值实例化模板子类方法时产生编译器错误
- 调用子类方法会导致分段错误
- 使用不受支持的类方法时引发编译器错误
- C 类方法声明返回错误
- 调用派生类方法时出现分段错误
- 模板类方法不会导致错误——这是标准的一部分
- std::线程类方法错误
- C++抽象类参数错误解决方法
- 类方法上的const编译错误
- 在类方法上使用指针:表达式的类型必须为bool错误
- 指向类方法错误c++11的指针数组
- 错误:在类方法声明中无效地使用void表达式
- 简单的一行类方法返回错误的值
- C++派生类调用基类方法给出了分段错误
- 使用boost::bind绑定了错误的模板类方法