将类的成员函数以函数指针的形式赋给另一个类

    技术2022-05-19  21

    typedef void (* HW_HANDLE)(int);

     

    class Switch{private:    HW_HANDLE   handle;public:    Switch(const HW_HANDLE h = 0 )      { handle=h; }    void Exec()                         { handle(1); }};

     

     

    void ShowLog(int v){    printf("this is %d/n",v);}

     

     

    class HdApi{public:    HW_HANDLE setConcreteSwitch;

        HdApi()                             { setConcreteSwitch=ShowLog; }};

     

    HdApi aHdapi;

    int _tmain(int argc, _TCHAR* argv[]){    Switch aSwitch(aHdapi.setConcreteSwitch);    aSwitch.Exec();

     

        return 0;}=======================================================

    vs2008上正常运行,但是在vc6.0上编译会失败???


    最新回复(0)