我尝试使用以下语句将成员函数调用为线程函数
boost::thread getURInHashThread(boost::bind(&Worker::run, this));
哪里
Worker
是类和
run()
是方法。我在同一个类的另一个成员函数中有这个语句Worker
所以我给了那个this
.
但是,我收到错误
error:bind is not a member of boost.
我无法弄清楚。请帮忙。提前感谢:)。
#include <boost/thread/thread.hpp>
#include <iostream>
class Test
{
public:
void Main() { boost::thread t(&Test::run, this); }
void run() { while(1){ std::cout << "some functionality here"; } }
};
int main()
{
Test test;
test.Main();
}
boost 线程在内部使用 bind 因此:
#include <boost/thread/thread.hpp>
#include <iostream>
class Test
{
public:
void Main() { std::cout << "hello" << std::endl; }
};
int main()
{
Test test;
boost::thread t(&Test::Main, test);
t.join();
}