Boost logo

Boost Users :

Subject: Re: [Boost-users] Event system using signals2
From: Frank Mori Hess (fmhess_at_[hidden])
Date: 2011-10-28 21:25:36


On Friday, October 28, 2011, Chris Cranford wrote:
> // base class for event system tracking
> class EventTrackedObject : public boost::signal2::trackable {
> public:
> EventTrackedObject() { }
> ~EventTrackedObject() { }
> };
>
> class MyObject : public EventTrackedObject {
> public:
> MyObject(EventDispatcher* pDispatcher) {
> pDispatcher->addListener(E_MY_EVENT,
> boost::bind(&MyObject::OnMyEvent, this));
> }
> ~MyObject() { }
>
> void OnMyEvent(void) { }
> };
>
> The problem with this I found is that the tracked object appears to be
> getting copied at the time the boost::bind is passing itself to the
> addListener() method. Is there a way to avoid this so that the
> tracked object's disconnect happens as expected?

I don't see how thats possible. Is it failing to disconnect just because
the bind functor is getting copied into a boost::function due to the
prototype of addListener? As was posted here recently, I don't think
boost::function support visit_each to allow detection of trackable objects.
One possibility is to make addListener pass its functor parameter as a
template type instead of a boost::function.




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