RE: [sigc] derive from sigc::trackable directly?



Dick Eimers wrote:
> sigc::trackable is the base class for objects with auto-disconnection.
> 
> I have a hierarchy like 'class Base', 'class DerivedX : public Base'
> and 'class DerivedY : public Base'. 
> 
> The auto-disconnection seems to work fine when both DerivedX and
> DerivedY derive from sigc::trackable directly (as in 'class DerivedY
> :  
> public Base, public sigc::trackable' etc.), however I've encountered
> some issues (segfaults) when Base derives from sigc::trackable and
> DerivedX and DerivedY don't (not directly that is).  
> 
> Is it necessary that every class that desires auto-disconnection to
> derive from sigc::trackable directly? Why?

Auto-disconnecting is fundamentally flawed when achieved via this baseclass. The problem is that if you derive from a class, there is a time between ~derived() is called and when it is disconnected in ~trackable(). If in between a call to one of its slots is done, these slots end in nirvana. I'd say the solution is to disconnect in the most derived dtor manually.

In your particular example, the order of destruction is DerivedX, Base, sigc::trackable (when Base derives from sigc::trackable). When DerivedX derives from sigc::trackable as you show, the order is the same (IIRC), but in this case it depends on the order, i.e. 
   struct X: base, sigc::trackable{..};
is not equivalent to
   struct X: sigc::trackable, base{..};

Uli



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]