Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Thread idiom
From: strasser_at_[hidden]
Date: 2010-03-13 15:24:21


Zitat von anony <janezz55_at_[hidden]>:

> On 03/13/10 19:58, strasser_at_[hidden] wrote:
>> Zitat von anony <janezz55_at_[hidden]>:
>>
>>> Is is possible to inherit from boost::thread and then store pointers to
>>> instantiated objects of such classes in say ptr_vector<>?
>>
>> why inherit? you can store boost::thread's (or classes that contain a
>> boost::thread) in a ptr_vector.
>
> Yes I can, but I need the object pointers too, not just thread pointers.

struct A{
public:
   A(){ // (1)
     boost::thread(bind(&A::start,this)).swap(this->thr);
   }
   void start(){
     ...
   }
private:
   boost::thread thr;
};

ptr_vector<A> avec;

(1) you could also construct A::thr upfront, but some compilers
generate warnings if the "this"-pointer is used in member initializers


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