Boost logo

Boost Users :

From: j.c. (jolix_at_[hidden])
Date: 2008-01-01 14:29:51


Was quite easy actually. :-)

#include <iostream>

#include <boost/bind.hpp>
#include <boost/signal.hpp>

namespace jc
{
     class task
     {
         public:
             task()
             {
                 // ...
             }

             ~task()
             {
                 // ...
             }

             void done()
             {
                 sig_finished(this);
             }

             /// signals
             boost::signal<void (task *)> sig_finished;
     };

     class bucket
     {
         public:
             bucket()
             {
                 // ...
             }

             ~bucket()
             {
                 // ...
             }

             void on_finished(task * t)
             {
                 std::cout << "on_finished:\n";
             }

             void set_task(task * t)
             {
                 t->sig_finished.connect(boost::bind(
                     &bucket::on_finished, this, t));
             }
     };

} // namepace jc

using namespace jc;

int main()
{
     task * t = new task;
     bucket * b = new bucket;
     b->set_task(t);
     t->done();

     delete t;
     delete b;

     return 0;
}



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net