Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-04-23 08:24:49


Jesper Bojesen wrote:
> I have a problem with the semantics of the the signal connect method.

[...]

> int main () {
> // Connect a HelloWorld slot
> HelloWorld hello;
> std::cout << "Main world at " << (void *) &hello << std::endl;
>
> boost::signal<void ()> sig;
> sig.connect(hello);
>
> sig ();
>
> std::cout << "Thats all folks!\n";
> return 0;
> }

[...]

> My problem is that the object signalled is not the same object that I
> subscribed
> to the signal.
>
> Is this really what was inteded ?

Yes.

> Is the any rationale behind this behaviour ?

Yes. Consider what would happen if hello were destroyed before the sig()
call.

> I am aware that I can get the behaviour that I expected if I create
> the slot using the bind function, however, I find the simpler syntax
> very nice, but its semantics are counter intuitive, and potentially
> very confusing.

Try sig.connect(ref(hello)) to request a reference to be stored.


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