继承和派生构造函数使用

#include<iostream>
#include<string>
using namespace std;
class person
{
private:
string name;
int age;
public:
display(void);
person(string p_name,int p_age)
{
name=p_name;
age=p_age;
}
};


person::display(void)
{
cout<<"姓名:"<<name<<endl;
cout<<"年龄:"<<age<<endl;
}


class student:public person
{
public:
string stuno;
show();
student(string s_name,int s_age,string s_stuno):person(s_name,s_age)
{
stuno=s_stuno;
}
};
student::show()
{
cout<<"学号"<<stuno<<endl;
display();
}
int main()
{
student st("校明",20,"2022");
st.show();
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_42433442/article/details/80807226
今日推荐