I\'ve started using boost::signals2 instead of my old signals-code. I\'m having a problem with administering multiple connections though. Here\'s my problem:
I have
I haven't tried it myself but according to boost documentation
When Can Disconnections Occur? (Intermediate)
Signal/slot disconnections occur when any of these conditions occur:
- The connection is explicitly disconnected via the connection's
disconnect
method directly, or indirectly via the signal'sdisconnect
method, orscoped_connection
's destructor.- An object tracked by the slot is destroyed.
- The signal is destroyed.
Unless you use a scoped_connection
the connection between a signal and slot will remain valid until either of them is destroyed. So as far as I understand you don't need to store connection objects in a vector. Just connect your signal to your slot as you are doing now.
When your observed object goes out of scope it will delete the connection by itself.
This is a much simpler design.