Boost.Signals2:在C++中实现事件处理
2012-10-29 13:48
99 查看
#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 */
相关文章推荐
- C++ FastDelegate 扩展,实现与.net类似的事件处理功能
- Java事件处理机制-事件监听器的实现方式
- 数字图像处理,小波变换一维Mallat算法的C++实现(matlab验证)
- 使用“事件监听/链式事件处理方式”实现window.onload同时调用多个函数
- VC 怎么实现对鼠标离开对话框时,事件的处理
- 使用 gperf 实现高效的 C/C++ 命令行处理
- 利用Java事件处理机制实现录制、回放功能
- vickate _触摸事件处理 实现UIView替代UIButton
- C++中 异常处理的 实现方式
- 实现 Fragment 触摸事件处理
- IOS学习——自定义View与使用block实现事件处理入门
- Android事件处理(按键、触摸屏和滚动球的一些实现细节)
- 利用Java事件处理机制实现录制、回放功能
- .Net/C# 封装磁盘目录文件搜索功能的工具类 (实现了与搜索相关的事件,以便插入客户处理代码)
- 使用c++的成员指针实现类似Borland VCL组件的事件回调
- lua 协程 | 协程实现消息机制(事件队列轮询处理机制)
- 单击事件的处理方式及注册窗体的创建之(四)Intent实现界面跳转传值
- Unity3d 使用UGUI实现button其他事件处理
- 跨浏览器实现自定义事件处理
- 滚动条QScroolBar实现滚屏功能(屏幕过大,覆盖wheelEvent来处理滑轮事件)