29 Sep
2006
29 Sep
'06
7:31 a.m.
Monica Gretzer wrote:
I want to use boost::thread to create threads that are member functions within a class. In all the examples I have seen, the thread function is defined globally.
This indeed should be a FAQ. class foo { public: foo() {} ~foo() {} // the following is what can be seen as kind of a "run" member void operator()(void) { std::cout << "Hello Thread!" << std::endl; } } Somewher you instantiate your class: foo my_foo; Then run it: boost::thread th(my_foo); Later join it: t.join(); You might also read about the boost::bind and functional, as the argument to the thread constructor is accepting a functional. Regards, Roland