HOWTO:访问成员函数指针?
发表于:2007-07-01来源:作者:点击数:
标签:
HOWTO:访问成员函数指针? #include iostream.h #include afxwin.h typedef double TYPE; class A { public: bool fun(TYPE n) //参数是引用类型可以统一处理(Very good!) { cout"A::fun() " n endl; return true; } void * GetP() { bool (A::* pFun)(TYPE
HOWTO:访问成员函数指针?
#include <
iostream.h>
#include <afxwin.h>
typedef double TYPE;
class A
{
public:
bool fun(TYPE& n) //参数是引用类型可以统一处理(Very good!)
{
cout<<"A::fun() "<< n <<endl;
return true;
}
void * GetP()
{
bool (A::* pFun)(TYPE&);
pFun = fun;
return *(void **)&pFun; // 注意:return (void *)&pFun;是错误的!
}
};
class B
{
public:
A a;
void Show(void * pVoid)
{
void * p = a.GetP();
A * pA = &a;
_asm
{
mov eax, pVoid //如果参数不是指针类型,则要用 lea eax, param
push eax
mov ecx, pA //在ecx中要放置对象的地址
call p
}
}
};
void main()
{
B b;
int i = 100;
double d = 100.236;
CString str("I am zht");
b.Show(&d);
}
原文转自:http://www.ltesting.net