HOWTO:访问成员函数指针?

类别:VC语言 点击:0 评论:0 推荐:
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://com.8s8s.com/it/it2875.htm