typedef boost::signals2::signal<void ()> signal_t;
class AAA {
public:
void Connect(const signal_t::slot_type& subscriber)
{
return m_sig.connect(subscriber);
}
void FireSignal()
{
m_sig();
}
private:
signal_t sig;
};
// Global
AAA a;
BBB b;
// Some scope
{
...
a.Connect(boost::bind(&BBB:foo, &b));
...
}
Now the temporary object returned by previous boost::bind goes out of scope and gets destroyed However the temporary object is passed to AAA::Connect by reference. Now lets say at some point, object a.FireSignal() is called, does the signal calls a function object that's already destroyed??? How does it work otherwise???
It makes a copy of it and keeps it.
The result of your to
boost::bindis sued to construct aslot_typewhich stores that as a member and then once it is passed tosignal::connectthe signal stores theslot_type, which means a copy of yourbindresult is stored within thesignaland that's the one used and called when the signal fires.I can't find a place where this is specificaly and axplicitly said but you can more or less conclude that from: