码迷,mamicode.com
首页 > 编程语言 > 详细

c++call back

时间:2017-05-18 09:50:43      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:window   ptr   virt   printf   ***   view   argv   har   call   

#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

标签:window   ptr   virt   printf   ***   view   argv   har   call   

原文地址:http://www.cnblogs.com/zhoug2020/p/6871607.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!