成员函数指针定义的方式:返回值(作用域 :: *指针变量)(形参类型)
=
成员函数指针获取的方式:& + 作用域 :: 成员函数名
#include <iostream>
using namespace std;
struct Stu
{
string name;
int age;
void showInfo()
{
cout<<"name : "<<name<<", age : "<<age<<endl;
}
};
int main()
{
Stu stu = {"zhsan", 18};
stu.showInfo();
void(Stu::*pfunc)() = &Stu::showInfo; //成员函数指针的 定义及 获取
(stu.*pfunc)(); // 使用
return 0;
}
运行结果: