
Is it possible to use a shared_ptr object in a signal?
I want something like
struct A{
...
void operator()(){ ... }
...
};
typedef boost::signal

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
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

James C. Sutherland a écrit :
mySignal.connect(a);
mySignal.connect(*a); // because connect copy the callback/functor. I guess you have to write a callable_shared_ptr or something. I d'idn't find it in Boost. -- Mickaël Wolff aka Lupus Michaelis Racine http://lupusmic.org Blog http://blog.lupusmic.org

On Dec 30, 2008, at 10:48 AM, Mickael Wolff wrote:
James C. Sutherland a écrit :
mySignal.connect(a);
mySignal.connect(*a); // because connect copy the callback/functor.
I guess you have to write a callable_shared_ptr or something. I d'idn't find it in Boost.
I cannot dereference the pointer because I must be able to modify the object, and as you point out the connect method copies the argument... James

James C. Sutherland:
I want something like
struct A{ ... void operator()(){ ... } ... }; typedef boost::signal
Signal; Signal mySignal; boost::shared_ptr<A> a( new A() ); mySignal.connect(a);
You can use mySignal.connect( boost::bind( &A::operator(), a ) ); Not pretty, but still a way to achieve what you want without a helper function (object). -- Peter Dimov http://www.pdplayer.com
participants (4)
-
James C. Sutherland
-
Mickael Wolff
-
Peter Dimov
-
Steven Watanabe