Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost thread: class member problem
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2011-01-27 09:17:19


"Patricia Hazel Shaw [phs]" <phs_at_[hidden]> writes:

> class Board{
> public:
> void pressButton(int button);
> void boxAction(int box);
> private:
> boost::thread_group threads;
> };
>
> void Board::pressButton(int button){
> if(button=1){
> threads.create_thread(&boxAction,1);

create_thread() takes a single callable object as the parameter, so if
you want to call a member function you must wrap it with bind:

threads.create_thread(boost::bind(&Board::boxAction,this,1));

Anthony

-- 
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++0x thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

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