Disconnecting

If you decide you no longer want your code to be called whenever a signal is emitted, you must remember the return value of connect(), which we've been ignoring until now.

connect() returns a sigc::connection object, which has a disconnect() member method. This does just what you think it does.

Also, sigc++ 3.6 adds sigc::scoped_connection. A scoped connection can be constructed or assigned from a normal/unscoped sigc::connection, whereupon it effectively takes ownership of the connection, and will automatically disconnect() it when the sigc::scoped_connection is destroyed (goes out of scope) or reassigned. This lets you tie whether a slot is called to the lifetime of a scoped connection object, e.g. as a class member, instead of having to manually disconnect. Scoped connections can be put in containers, or made ref-counted via std::shared_ptr. See the sigc::scoped_connection class documentation for examples.