zoukankan      html  css  js  c++  java
  • C++ Boost signal2信号/插槽

    #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;
    }
    

      

  • 相关阅读:
    Laravel 框架
    tp5
    jq关于对象类型的判断
    简易的 js 留言板
    学习任务
    实验报告:指针与地址
    C语言数据类型
    嗯,关于 nanxI 的50条~(算是自我介绍吧)
    初学C语言
    dropload.js
  • 原文地址:https://www.cnblogs.com/m-zhang-yang/p/9084783.html
Copyright © 2011-2022 走看看