Boost logo

Boost Users :

Subject: Re: [Boost-users] [Newbie] How to create a class member thread
From: Igor R (boost.lists_at_[hidden])
Date: 2009-02-24 12:49:52


>
> 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_ptr<boost::thread> _thread;
};



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