$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
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;
};