24 Feb
2009
24 Feb
'09
5:49 p.m.
I have a thread object stored in a class:
class MyClass {
private: void Init(); boost::thread _thread; }
How can I create it in the implementation code?
MyClass::Init() { // start thread here... }
This way thread object is created by default contructor. You probably wanted something like this: void threadFunc(); MyClass::MyClass() : _thread(&threadFunc) {}; Or: class MyClass { private: void Init() { _thread.reset(new boost::thread(&threadFunc)); } boost::shared_ptrboost::thread _thread; };