C++快速入门 第二十八讲:多继承(multiple inheritance)
1 多继承语法: 2 3 //助教类既继承于老师类,又继承于学生类 4 class Assistant:public Teacher,public Student 5 ; 7 8 当遇到的问题无法只用一个“是一个”关系来描述的时候,就是多继承出场的时候。例即是学生,又是人,还是助教。 9 10 #include <iostream> 11 #include <string> 12 13 using namespace std; 14 15 #include <string> 16 //人类 17 class Person 18 ; 25 Person::Person(string theName)//构造函数实现 26 29 void Person::introduce()//introduce()函数实现 30 33 34 //老师类继承于人类 35 class Teacher:public Person 36 ; 45 Teacher::Teacher(string theName,string theClass):Person(theName)//老师的名字继承于人类中的名字 46 49 void Teacher::teach() 50 53 void Teacher::introduce() 54 57 58 //学生类继承于人类 59 class Student:public Person 60 ; 69 Student::Student(string theName,string theClass):Person(theName)//学生名字继承于人类中的名字 70 73 void Student::attendClass() 74 77 void Student::introduce() 78 81 82 //助教类既继承于老师类,又继承于学生类 83 class Assistant:public Teacher,public Student 84 ; 90 Assistant::Assistant(string theName,string classTeaching,string classAttending):Teacher(theName, classTeaching),Student(theName,classAttending) 91 96 void Assistant::introduce() 97 101 102 int main() 103
下一篇:C++快速入门 第十讲:复杂的数据类型——指针和数组
C/C++
lbc文件怎么看,lbc文件用什么打开?
lab文件怎么看,lab文件用什么打开?
pim文件怎么看,pim文件用什么打开?
pip文件怎么看,pip文件用什么打开?
pig文件怎么看,pig文件用什么打开?
pid文件怎么看,pid文件用什么打开?
pie文件怎么看,pie文件用什么打开?
0文件怎么看,0文件用什么打开?
picnc文件怎么看,picnc文件用什么打开?
pict文件怎么看,pict文件用什么打开?