在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
#include "stdafx.h" #include "boost/signals2.hpp" #include "boost/bind.hpp" #include "boost/function.hpp" #include <iostream> using namespace std; class Button{ private: typedef boost::signals2::signal<void(int,int)> singalDef; typedef singalDef::slot_type slotType; private: //信号 singalDef m_singal; boost::signals2::connection m_connect; public: //信号的绑定函数 boost::signals2::connection Connect(const slotType& slot){ return m_singal.connect(slot); } //信号的发射 void SendSignal(int x,int y){ m_singal(x,y); } }; //对button的信号进行处理 class ButtonPro{ public: ButtonPro(Button* button):m_button(button){ //绑定信号和槽 m_button->Connect(boost::bind(&ButtonPro::slotButton,this,_1,_2)); } //槽函数 void slotButton(int x,int y){ cout<<"输出:"<<x<<", "<<y<<endl; } private: Button* m_button; }; int _tmain(int argc, _TCHAR* argv[]) { Button* pb = new Button(); ButtonPro bp(pb); //发出一个信号 pb->SendSignal(1,2); delete pb; return 0; }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论