如何使用BOOST 信号(一)
信号与插槽-概念
signal :Signals represents callbacks with multiple targets, and are also called publisher or events in similar systems.
slot : Signals are connected to some set of slots, which are callback receivers(also called event targets or subscribers), which are called when the signal is "emitted."
Exp 1 : call a single slot.
#include <boost/signal.hpp>
#include <boost/thread/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
using namespace std;
struct Hello_World
{
void operator ()() const
{
wcout << " Hello World " << endl;
}
};
int main()
{
boost::signal<void ()> sig;
boost::this_thread::sleep(boost::posix_time::milliseconds(5000));
Hello_World hw;
sig.connect(hw);
sig();
return 0;
}
Exp 2 :call multiple slots.
#include <boost/signal.hpp>
#include <boost/thread/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
using namespace std;
using namespace boost;
struct Hello
{
void operator ()() const
{
cout << " HELLO " << endl;
}
};
struct World
{
void operator ()() const
{
cout <<