Using a member function

Suppose you found a more sophisticated alien alerter class on the web, such as this:

class AlienAlerter : public sigc::trackable
    AlienAlerter(char const* servername);
    void alert();
    // ...

(Handily it derives from sigc::trackable already. This isn't quite so unlikely as you might think; all appropriate bits of the popular gtkmm library do so, for example.)

You could rewrite your code as follows:

int main()
    AlienDetector mydetector;
    AlienAlerter  myalerter("localhost");	// added
    mydetector.signal_detected.connect( sigc::mem_fun(myalerter, &AlienAlerter::alert) ); // changed;

    return 0;

Note that only 2 lines are different - one to create an instance of the class, and the line to connect the method to the signal.

This code is in, which can be compiled in the same way as