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