函数指针Demo

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;
}
原文地址:https://www.cnblogs.com/tuzhiye/p/1759633.html