开发者

boost multiple calls to class method

开发者 https://www.devze.com 2023-02-25 10:54 出处:网络
In boost::thread is it possible to call a class method with out making the class callable and implementing the void开发者_运维技巧 operator()() as in just call the class method

In boost::thread is it possible to call a class method with out making the class callable and implementing the void开发者_运维技巧 operator()() as in just call the class method

   for(int i=0;i<5;i++)
    boost::thread worker(myclass.myfunc,i,param2);

I get an error <unresolved overloaded function type>

Actually I would prefer to know the same for zi::thread


boost::thread doesn't need anything special, it will work exactly as you want (minus syntax errors):

for (int i = 0; i != 5; ++i)
    boost::thread worker(&myclass::myfunc, myclassPointer, i, param2);

From the boost.thread docs:

template <class F,class A1,class A2,...>
thread(F f,A1 a1,A2 a2,...);

Effects: As if thread(boost::bind(f, a1, a2, ...)). Consequently, f and each aN are copied into internal storage for access by the new thread.


For boost::thread you can use boost::bind to call a class member function.

myclass obj;
for(int i=0;i<5;i++)
        boost::thread worker(boost::bind(&myclass::myfunc,&obj,i,param2));
0

精彩评论

暂无评论...
验证码 换一张
取 消