#include <iostream>
#include <string>
using namespace std; class Test{
private:
string name;
public:
string GetName(){
return name;
}
void SetName(string name){
this->name=name;
} }; int main(){
cout<<"----------------"<<endl; Test* t = new Test(); //方案1 使用 auto, 不用 GetPtr 或 SetPtr 函数定义
//auto funcGet = &Test::GetName;
//auto funcSet = &Test::SetName; //(t->*funcSet)("张三");
//string name = (t->*funcGet)();
//cout<<name<<endl; //方案2 先定义两个 函数定义, 然后再调用这个函数定义
typedef string (Test::*GetPtr)();
typedef void (Test::*SetPtr)(string); GetPtr funcGet = &Test::GetName;
SetPtr funcSet = &Test::SetName; (t->*funcSet)("张三");
string name = (t->*funcGet)();
cout<<name<<endl; cout<<"----------------"<<endl;
cin.get();
}