在c++ 里怎样实现一个成员函数调用另一个成员函数,同类的

如题所述

#include <iostream>
#include <string>
using namespace std;

class Person
{
private:
string name;//姓名,如果不需要该信息,请自行删去
char sex;//性别
int age;//年龄
public:
Person(string strn,char chs,int inta ) 
{
name=strn;
sex=chs,
age=inta;
}
Person(){}
void Action() const{
cout<<name<<" is running..."<<endl;
}
void Print() const {
cout<<"name: "<<name<<endl;
cout<<"sex: "<<sex<<endl;
cout<<"age: "<<age<<endl;
Action();//调用另一个成员函数Action()
 }
};
int  main()
{
Person a("Mr. Zhang",'M',19);
a.Print();//显示信息

return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答