boost::thread 无效使用非静态成员函数

Kru*_*cho 2 c++ boost

我从 boost::thread 库开始,我有一个这样的代码:

Class::Class()
{
    ...
    boost::thread thread_foo(Class::foo);
    ...
}

Class::foo()
{
    //do stuff
}
Run Code Online (Sandbox Code Playgroud)

但是当我编译它时,我有一个“非静态成员函数的无效使用”,我真的不知道出了什么问题,因为当我查看文档时,这是创建线程的方式。

我确定这是一个愚蠢的错误,但我只是没有看到。

谢谢

For*_*veR 5

你也应该发送对象。

boost::thread thread_foo(&Class::foo, this);
Run Code Online (Sandbox Code Playgroud)

或者

boost::thread thread_foo(boost::bind(&Class::foo, this));
Run Code Online (Sandbox Code Playgroud)