Boost logo

Boost Users :

From: Cory Nelson (phrosty_at_[hidden])
Date: 2006-02-14 17:07:37


You need to correctly specify the member function pointer, and pass in
the 'this' pointer. Try boost::bind(&MyClass::ChildThreadFunc, this,
ii)

On 2/14/06, Steven Wooding <steve.apo_at_[hidden]> wrote:
> Hi,
>
> I've had a good search on the mailing list and while some posts have
> got close to my problem and given me a few glues, my code does't quite
> work the way I want it to.
>
> My goal is to have a (non-static) class member function run in a child
> thread + passing a parameter to it. The code I've got at the moment
> goes something like this:
>
> void MyClass::spawn_threads()
> {
> for ( int ii = 0; ii < num_threads; ++ii)
> {
> threadGroup.create_thread( boost::bind( ChildThreadFunc, _1, ii));
> }
> }
>
> void MyClass::ChildThreadFunc( int &threadNumber)
> {
> // Does some work
> }
>
> I get the following error on the create_thread line:
>
> error: no matching function call to bind(<unknown type>, boost::arg<1>&, int&)
> cadiates are: .... boost:bind(F, A1, A2)[ with F= void
> (MyClass::*)(int&), A1=boost:arg<1>, A2=int]
>
> I'm confused by the <unknown type> business. How do I tell it the correct type?
>
> Maybe someone could point out where I've erred.
>
> Cheers,
>
> Steve.
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

--
Cory Nelson
http://www.int64.org

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net