我们想定义一个指向类的函数的指针
在此 我们可以复习一下 函数指针的定义
例如:
void AA(int n)
{
cout << "AA" << " " << n << endl;
}
AA函数的指针定义格式为:
void (*p)(int) = &AA;
同理:
class Person
{
public :
void Show(int a)
{
cout << "Person::" << " " < }
};
Person的Show函数的指针可定义为
void (Person::*p1)(int) =& Person::Show;
在主函数中我们
通过对象或对象指针调用对象里的函数指针 格式为.*p1 ->*p1
Person P;
如
(P.*p1)(100);
完整代码如下
#includeusing namespace std; void AA(int n) { cout << "AA" << " " << n << endl; } class Person { public : void Show(int a) { cout << "Person::" << " " <*p1 typedef void (Person::* PFUN)(int); PFUN p2 = (PFUN)&Chinese::Show; (P.*p2)(300); return 0; }



