当前位置: 技术问答>linux和unix
不同编译器对成员函数指针的解读
来源: 互联网 发布时间:2017-05-15
本文导语: 在THash.h中: class TMemBase; //声明类 ...
在THash.h中:
在TMemBase.h中:
setFunc的实现:
问题在THash类中使用传入的成员函数指针的时候,G++编译器下编译是没有问题的,在xlC编译器下出现如下问题:
"THash.cpp", line 94.31: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
"THash.cpp", line 140.34: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
"THash.cpp", line 144.52: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
"THash.cpp", line 259.36: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
"THash.cpp", line 282.36: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
其中94行代码如下:
求大神指点!
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;
m_cfunc = (int (TMemBase::*)(void *, void *, void *))cfunc;
m_pMem->SetFunc(this, m_pfunc, m_rfunc, m_cfunc);
}
问题在THash类中使用传入的成员函数指针的时候,G++编译器下编译是没有问题的,在xlC编译器下出现如下问题:
"THash.cpp", line 94.31: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
"THash.cpp", line 140.34: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
"THash.cpp", line 144.52: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
"THash.cpp", line 259.36: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
"THash.cpp", line 282.36: 1540-0251 (S) The "->*" operator cannot be applied to the undefined class "class TMemBase".
其中94行代码如下:
int THash::FRelace(void *key, void *val, bool lock)
{
int ret = 0;
void *v = NULL;
_LOCK_KEY();
ret = m_shm->shb_find(key, (void **)&v); //第94行
if (ret == _SHM_HASH_FOUND) {
ret = (m_pbase->*m_rfunc)(key, v, val);
} else if (ret == _SHM_HASH_SYS_ERROR) {
ret = -2;
} else {
ret = m_shm->shb_add(key, val);
}
_UNLOCK_KEY();
return ret;
}
求大神指点!
|
代码贴全点,变量声明,函数声明
最后一段代码太模糊了
最后一段代码太模糊了