在 boost::thread 中,是否可以调用类方法而无需使类可调用并实现 void operator()() 就像调用类方法一样
for(int i=0;i<5;i++)
boost::thread worker(myclass.myfunc,i,param2);
我收到一个错误<unresolved overloaded function type>
其实我更愿意知道同样的 zi::thread
在 boost::thread 中,是否可以调用类方法而无需使类可调用并实现 void operator()() 就像调用类方法一样
for(int i=0;i<5;i++)
boost::thread worker(myclass.myfunc,i,param2);
我收到一个错误<unresolved overloaded function type>
其实我更愿意知道同样的 zi::thread
boost::thread
不需要任何特殊的东西,它会完全按照你的意愿工作(减去语法错误):
for (int i = 0; i != 5; ++i)
boost::thread worker(&myclass::myfunc, myclassPointer, i, param2);
template <class F,class A1,class A2,...>
thread(F f,A1 a1,A2 a2,...);
效果:好像
thread(boost::bind(f, a1, a2, ...))
。因此,f
每个aN
都被复制到内部存储中以供新线程访问。
对于 boost::thread,您可以使用 boost::bind 调用类成员函数。
myclass obj;
for(int i=0;i<5;i++)
boost::thread worker(boost::bind(&myclass::myfunc,&obj,i,param2));