我试图创建一个简单的线程并让它执行。
我的功能定义是:
void MyClass::myFunction()
{
//Do Work
}
我正在创建线程并执行它:
std::thread t1(myFunction);
编译我的代码后,我收到以下错误:
error C3867: function call missing argument list; use '&MyClass::myfunction' to create a pointer to member.
由于我的函数没有采用任何参数,我假设我在创建我的线程时错误地声明它?任何帮助将不胜感激,谢谢!!
答案 0 :(得分:4)
示例强>:
class A
{
public:
void foo() { cout << "foo"; }
static void bar() { cout << "bar"; }
};
int main() {
std::thread t1(&A::foo, A()); // non static member
t1.join();
std::thread t2(&A::bar); // static member (the synthax suggested by the compiler)
t2.join();
return 0;
}