代码人生的小狗窝

一行行枯燥的代码,却描绘出人生的点点滴滴

您现在的位置是:首页>_AIX

不同编译器对成员函数指针的解读解决办法

发布时间:2020-01-29浏览(2137)

    不同编译器对成员函数指针的解读
    在THash.h中:

    class TMemBase; //声明类                                                                
                                                                                    
    typedef int (TMemBase::*PFUNC)(void *, void *, void *); 

    class THash{  

    private:

    void SetFunc(TMemBase *pbase, PFUNC pfunc, RFUNC rfunc, CFUNC cfunc);

    TMemBase *m_pbase;

    }; 


    在TMemBase.h中:

    #include "THash.h"  

    class TMemBase{ 

    private:

    virtual int Print(void *key, void *val, void *data) = 0;

    virtual int Check(void *key, void *val, void *pdata) = 0; 

    virtual void GetKVlen(size_t &klen, size_t &vlen) = 0;

    void SetFunc();

    PFUNC m_pfunc;                                                          
                                                                                    
    RFUNC m_rfunc;                                                          
                                                                                    
    CFUNC m_cfunc;

    };


    setFunc的实现:
    void TMemBase::SetFunc()                                                        
    {                                                                               
        PFUNC pfunc =  &TMemBase::Print;                                            
        RFUNC rfunc = &TMemBase::UpVale;                                            
        CFUNC cfunc = &TMemBase::Check;                                             
                     
        m_pfunc =  (int (TMemBase::*)(void *, void *, void *))pfunc;                
        m_rfunc =  (int (TMemBase::*)(void *, void *, void *))rfunc;