Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr and signals
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-12-30 12:47:03


AMDG

James C. Sutherland wrote:
> Is it possible to use a shared_ptr object in a signal?
>
> I want something like
>
> struct A{
> ...
> void operator()(){ ... }
> ...
> };
> typedef boost::signal<void()> Signal;
> Signal mySignal;
>
> boost::shared_ptr<A> a( new A() );
> mySignal.connect(a);
>
> The trouble seems to be getting the signal to dereference the pointer
> when the callback is made...
>
> Any tips?

Wrap the shared_ptr in a function object

struct deref_call {
    void operator()() const {
        (*f)();
    }
    boost::shared_ptr<A> f;
};

In Christ,
Steven Watanabe


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