Cpp/DesignPatterns/Observer/Sigc.cpp
void exemple02()
{
    std::cout << "Example 02" << std::endl;

    Worker worker;

    // Connection to a function ...
    sigc::connection c = worker.m_signal1Finished.connect(sigc::ptr_fun(longOperationFinished));

    // Destroyed on runtime
    {
        Notifier notifier;
        worker.m_signal1Finished.connect(sigc::mem_fun(notifier, &Notifier::longOperationFinished));
    } // notifier no longer exists

    std::cout << "Reaction 01:" << std::endl;
    worker.doLongOperation(); // function reacts

    std::cout << "Reaction 02:" << std::endl;
    c.disconnect();
    worker.doLongOperation(); // No reaction
}
// ****************************************************************************
//! \brief Make the notifier destroyed after its subscription but before
//! receiving its message.
// ****************************************************************************
\brief Make the notifier destroyed after its subscription but before
receiving its message.
\ brief Make the notifier destroyed after its subscription but before receiving its message .
void exemple02()
{
    std::cout << "Example 02" << std::endl;
    Worker worker;
    sigc::connection c = worker.m_signal1Finished.connect(sigc::ptr_fun(longOperationFinished));
    {
        Notifier notifier;
        worker.m_signal1Finished.connect(sigc::mem_fun(notifier, &Notifier::longOperationFinished));
    } 
    std::cout << "Reaction 01:" << std::endl;
    worker.doLongOperation(); 
    std::cout << "Reaction 02:" << std::endl;
    c.disconnect();
    worker.doLongOperation(); 
}
void exemple02 ( ) { std :: cout << " " << std :: endl ; Worker worker ; sigc :: connection c = worker . m_signal1Finished . connect ( sigc :: ptr_fun ( longOperationFinished ) ) ; { Notifier notifier ; worker . m_signal1Finished . connect ( sigc :: mem_fun ( notifier , & Notifier :: longOperationFinished ) ) ; } std :: cout << " " << std :: endl ; worker . doLongOperation ( ) ; std :: cout << " " << std :: endl ; c . disconnect ( ) ; worker . doLongOperation ( ) ; }
\brief Make the notifier destroyed after its subscription but before
receiving its message.
\ brief Make the notifier destroyed after its subscription but before receiving its message .
// Connection to a function ... // Destroyed on runtime // notifier no longer exists // function reacts // No reaction