//39指向類成員(數(shù)據(jù)函數(shù))的指針
//類 數(shù)據(jù)成員 函數(shù)成員
成員類型 類名::* 指針名 = &類名::成員名
int a;int p = &a;
函數(shù)返回類型 類名::( 函數(shù)指針名)(參數(shù)列表) = &類名::成員函數(shù)名
void fun(); void( * pf)()=&func();
//對(duì)象
// .* ->* 對(duì)象.數(shù)據(jù)成員指針 對(duì)象指針->數(shù)據(jù)成員指針
(對(duì)象.成員函數(shù)指針)() (對(duì)象指針->成員函數(shù)指針)()
class Stu
{
public:
Stu(string sn,int ia):
name(sn),age(ia){}
void print()
{
cout<<name<<"-"<<age<<endl;
}
public:
string name;
int age;
};
int main()
{
Stu s1("zhaosi",39);
Stu s2("aobaniu",79);//棧
Stu *pp = new Stu(“nigulasi”,60);
int Stu::*pa = &Stu::age;
cout<<s1.name<<s2.name<<endl;
cout<<s1.*pa<<s2.*pa<<endl;//結(jié)果一樣和上面
cout<<pp->*pn<<endl;
void (Stu::*pf)()=&Stu::print;
s1.print();s2.print();
s1.(*pf)();s2.(*pf)();
(pp->*pf)();
return 0;
}
//對(duì)象 數(shù)據(jù)成員 函數(shù)成員