且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c++call back

更新时间:2022-09-15 23:14:16

#include "stdafx.h"
struct A;

typedef void(A::*MemFuncPtr) (int* e);

class A
{
    int a;
}; 

class View : public A
{
public:
    virtual void test() { printf("test A\n"); }
};

class Window : public View
{
public:
    virtual void test() { printf("test A\n"); }
    void func(int * b) { (void)b; printf("************\n"); }
};


typedef void(*HandlerNoParam)();
typedef void(*Handler1Param)(void* receiver);
typedef void(*Handler2Param)(void* receiver, int* e);

void test1()
{
    printf("no parameter test:\n");
}

void test2(void* receiver)
{
    (void)receiver;
    printf("1 parameter test:\n");
}

void test3(void* receiver, int* e)
{
    (void)receiver;
    (void)e;
    printf("2 parameter test:\n");
}



int _tmain(int argc, _TCHAR* argv[])
{
    Handler2Param p0 = (Handler2Param)test2;
    p0(NULL, 0);

    MemFuncPtr p = (MemFuncPtr)&Window::func;
    Window a;
    (a.*p)(NULL);
    getchar();
    return 0;
}
c++call back

 本文转自莫水千流博客园博客,原文链接:http://www.cnblogs.com/zhoug2020/p/6871607.html,如需转载请自行联系原作者