zoukankan      html  css  js  c++  java
  • c++ 宏定义声明类,并在类中实现回调

    #include <iostream>
    #include <windows.h>
    #include <string>
    using namespace std;
    typedef void ( *tFunc )( void );
    class subclass{
    public:
        virtual tFunc setFun() = 0;
    };
    #define __SetCallBack1(op_name,wrapper_name) 
    class op_name:public subclass{ 
    public:
    op_name(tFunc func):mfunc(func){}
    tFunc setFun(){return mfunc;}
    tFunc mfunc;
    };  
    inline op_name  wrapper_name(tFunc func){return op_name(func);}
    
    #define _SetCallBack1(name) __SetCallBack1(name##T,name)
    _SetCallBack1(SetInitFunc)
    
    template<class OP1>
    void InitControl( OP1 op1)
    {
        subclass *msc=&op1;
        tFunc f = msc->setFun();
        f();
    }
    void  printss()
    {
        cout<<"hello"<<endl;
    }
    int main()
    {
        
        InitControl(SetInitFunc(printss));
        cin.get();
        return 0;
    }
  • 相关阅读:
    leetcode
    Vim i和a差别
    HDU-4643-GSM(DFS)
    使用可编程电源自动化输出电源
    如何使用全局变量
    异步和同步
    启动界面
    鼠标右键弹出菜单
    Qt+excel
    Qt+数据库
  • 原文地址:https://www.cnblogs.com/shit/p/3229827.html
Copyright © 2011-2022 走看看