【发布时间】:2013-03-22 00:07:38
【问题描述】:
我正在尝试使用 C++11 的 std::thread 类来运行一个类的成员函数以并行执行。
头文件的代码类似:
class SomeClass {
vector<int> classVector;
void threadFunction(bool arg1, bool arg2);
public:
void otherFunction();
};
cpp文件类似于:
void SomeClass::threadFunction(bool arg1, bool arg2) {
//thread task
}
void SomeClass::otherFunction() {
thread t1(&SomeClass::threadFunction, arg1, arg2, *this);
t1.join();
}
我在 Mac OS X 10.8.3 下使用 Xcode 4.6.1。我使用的编译器是 Xcode 附带的 Apple LLVM 4.2。
上面的代码不起作用。编译器错误说"Attempted to use deleted function"。
在线程创建行显示以下按摩。
In instantiation of function template specialization 'std::__1::thread::thread<void (SomeClass::*)(bool, bool), bool &, bool &, FETD2DSolver &, void>' requested here
我是 C++11 和线程类的新手。有人可以帮我吗?
【问题讨论】: