#include <iostream>
#include <boost/signals2/signal.hpp>
using std::cout;
using std::endl;
struct A
{
void f() {
int a = 2;
event(1, &a);
}
boost::signals2::signal<void (int, int*)> event;
};
void h5(int i, int* p) {cout << "h5\t" << i << " " << *p << endl;}
struct B
{
A a;
void g() {
a.event.connect(std::bind(&B::h, this, std::placeholders::_1, std::placeholders::_2));
a.event.connect(std::bind(&B::h, this, std::placeholders::_1, std::placeholders::_2));
a.event.connect(std::bind(&B::h1, this, std::placeholders::_2, std::placeholders::_1));
a.event.connect(std::bind(&B::h2, this, 2, std::placeholders::_1, std::placeholders::_2));
a.event.connect(std::bind(&B::h3, this, std::placeholders::_2));
a.event.connect(std::bind(&B::h4, this));
a.event.connect(h5);
a.event.connect([](int i, int* p) {cout << "h6\t" << i << " " << *p << endl;});
a.f();
}
void h(int i, int* p) {cout << "h\t" << i << " " << *p << endl;}
void h1(int* p, int i) {cout << "h1\t" << i << " " << *p << endl;}
void h2(int i, int j, int* p) {cout << "h2\t" << i << " " << j << " " << *p << endl;}
void h3(int* p) {cout << "h3\t" << *p << endl;}
void h4() {cout << "h4" << endl;}
};
int main()
{
B b;
b.g();
return 0;
}
/*
h 1 2
h 1 2
h1 1 2
h2 2 1 2
h3 2
h4
h5 1 2
h6 1 2
*/
Boost.Signals2:在C++中实现事件处理
最新推荐文章于 2024-05-22 15:45:27 发布