采用取成員函數指針的地址的方法
/* VS
class AbstractMethod
{
public:
virtual void show(){} // =
void fun()
{
cout <<
}
void fun
{
cout <<
}
};
int main()
{
// 定義成員函數指針類型
typedef void (AbstractMethod::*MFP)(void);
// 轉化函數指針為別的指針
MFP mfp
unsigned* tmp = (unsigned*)&mfp
cout << hex << *tmp << endl;
MFP mfp
tmp = (unsigned*)&mfp
cout << hex << *tmp << endl;
MFP mfp
tmp = (unsigned*)&mfp
cout << hex << *tmp << endl;
// 通過轉化後的指針調用成員函數
AbstractMethod am;
MFP* addr = (MFP*)tmp;
(am
(am
return
}
驗證上述方法取得的成員函數地址是否正確
Copyright@戴維
From:http://tw.wingwit.com/Article/program/net/201311/13364.html