class CStudentTeacher: public CStudent, public CTeacher{//多重继承 public: CStudentTeacher(double Cost, double Page,int Age):CStudent(Cost),CTeacher(Page),age(Age){}; CStudentTeacher(CStudentTeacher &c)//定义拷贝构造函数 { age=c.age; cost=c.cost; page=c.page; } void operator=(CStudentTeacher &c)//重载赋值运算符 { age=c.age; cost=c.cost; page=c.page; } void Showdata() { cout<<"Age and Cost and Page per month of new person is "<<age<<" "<<cost<<" "<<page<<endl; } private: int age; };
int main() { CStudent s1(600.0); s1.ShowNum(); cout<<"Cost per month of new person is "<<s1.Getdata()<<endl; CStudent s2(s1); s2.ShowNum(); cout<<"Cost per month of new person is "<<s2.Getdata()<<endl; CStudent s3=s1; s3.ShowNum(); cout<<"Cost per month of new person is "<<s3.Getdata()<<endl; CTeacher c1(1500.0); c1.ShowNum(); cout<<"Page per month of new person is "<<c1.Getdata()<<endl; CTeacher c2(c1); c2.ShowNum(); cout<<"Page per month of new person is "<<c2.Getdata()<<endl; CTeacher c3=c1; c3.ShowNum(); cout<<"Page per month of new person is "<<c3.Getdata()<<endl; CStudentTeacher s4(500.0,1000.0,25); CPerson::m_sCount--; s4.ShowNum(); s4.Showdata(); CStudentTeacher s5(s4); CPerson::m_sCount--; s5.ShowNum(); s5.Showdata(); CStudentTeacher s6=s4; CPerson::m_sCount--; s6.ShowNum(); s6.Showdata();