指向 Data Member / Member Function 的指针的类型

这个用得少,总忘。

// VC++ 2005 /Gd class Foo { public: void __thiscall f_thiscall(){} // 注: VC++ 2005 以前, 程序员不能显式使用 // __thiscall. 因为 __thiscall 还不是 // 关键字. void __fastcall f_fastcall(){} void __stdcall f_stdcall(){} void __cdecl f_cdecl(){} public: int m_data; }; int main() { int* pi = &Foo::m_data; void (__cdecl Foo::*pmf)() = &Foo::f_thiscall; void (*pf)() = &Foo::f_thiscall; void (__fastcall *pf_fastcall)() = &Foo::f_fastcall; void (__stdcall *pf_stdcall)() = &Foo::f_stdcall; void (__cdecl *pf_cdecl)() = &Foo::f_cdecl; return 0; } 

// 编译错误信息 (18) : error C2440: 'initializing' : cannot convert from 'int Foo::* ' to 'int *' (19) : error C2440: 'initializing' : cannot convert from 'void (__thiscall Foo::* )(void)' to 'void (__cdecl Foo::* )(void)' (20) : error C2440: 'initializing' : cannot convert from 'void (__thiscall Foo::* )(void)' to 'void (__cdecl *)(void)' (21) : error C2440: 'initializing' : cannot convert from 'void (__fastcall Foo::* )(void)' to 'void (__fastcall *)(void)' (22) : error C2440: 'initializing' : cannot convert from 'void (__stdcall Foo::* )(void)' to 'void (__stdcall *)(void)' (23) : error C2440: 'initializing' : cannot convert from 'void (__cdecl Foo::* )(void)' to 'void (__cdecl *)(void)' 

你可能感兴趣的:(c,function,Class)