小弟有C语言小程序一个,其中一句话不懂,请教下各位大虾.
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;
#define AEEVTBL(iname) iname##Vtbl
#define AEEINTERFACE(iname) \
typedef struct AEEVTBL(iname) AEEVTBL(iname); \
struct AEEVTBL(iname)
#define AEEGETVTBL(p, iname) (*((AEEVTBL(iname)**)p))
//声明虚函数列表
AEEINTERFACE(APP)
{
void (*pf)();
};
/*
tydef struct APPVtbl APPVtbl;
struct APPVtbl
{
void (*pf)();
}
*/
typedef struct APP
{
AEEVTBL(APP) *pvt;
}APP;
/*
tydef struct APP
{
APPVtbl *pvt;
}
*/
#define FUN(p) AEEGETVTBL(p, APP)->pf()
/*
(*((AEEVTBL(APP)**)p))->pf()
(*(APPVtbl**)p))->pf()
*/
void f()
{
cout<<"f() is ok"<<endl;
}
void g()
{
cout<<"g() is ok"<<endl;
}
//函数列表1
AEEVTBL(APP) vable = { f };
//函数列表2
AEEVTBL(APP) vable2 = { g };
int main(int argc, char* argv[])
{
APP* pMe = (APP*)malloc(sizeof(APP));
pMe->pvt = &vable;
FUN(pMe);
pMe->pvt = &vable2;
FUN(pMe);
/*
FUN(pMe) 转换后为 (*((APPVtbl**)pMe))->pf()
请问下 (*((APPVtbl**)pMe)) 是什么 意思?
*/
free(pMe);
return 0;
}