博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

函数指针Demo

Posted on 2010-06-17 16:21  Zhiyett  阅读(182)  评论(0编辑  收藏  举报

DemoProject1工程:

void HandlerProc(int n1, int n2, int n3)
{
    switch(n1)
    {
    }
}

void main()
{
    g_pDemo->Init(HandlerProc);
}

DemoProject2工程:

typedef void (* InfoHandler)(int, int, int);
class IDemo
{
public:
    virtual bool Init(InfoHandle handler) = 0;
    virtual void ShutDown() = 0;
};

#define g_pDemo GetDemo();

class CDemo: public IDemo
{
public:
    virtual bool Init(InfoHandle handler){m_InfoHandler = handler;};
    virtual void ShutDown(){ if(m_InfoHandler~=NULL){m_InfoHandler(1, 1, 0);}};
private:
    InfoHandler m_InfoHandler;
}