#include <iostream>
#include <string>
using namespace std;
class student
{
private:
int num;
string name;
string sex;
public:
student(){num=1;name="Tom";sex="BOY";}
void display()
{
cout<<"thestudent's information is:"<<endl;
cout<<"num "<<num<<endl;
cout<<"name "<<name<<endl;
cout<<"sex "<<sex<<endl;
}
int get_num(){return num;}
string get_name(){return name;}
string get_sex(){return sex;}
};
class teacher
{
private:
int num;
string name;
string sex;
string teach;
public:
void set_teacher(student &s){num=s.get_num();name=s.get_name();sex=s.get_sex();}//here
void display()
{
cout<<"theteacher's information is:"<<endl;
cout<<"num "<<num<<endl;
cout<<"name "<<name<<endl;
cout<<"sex "<<sex<<endl;
}
};
int main()
{
student s1;
teacher t1;
s1.display();
cout<<"aftergraate from the school and become a teacher"<<endl;
t1.set_teacher(s1);
t1.display();
return 0;
}
本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。