题目内容
程序的目的是实现动态多态性,在类层次设计中共5处错误,请指出,并改正。1.#include 2.#include3.using namespace std;4.class People5.{ public:6. void SayHi(){cout<<"HI!我是一个人!\n";}7.};8.class Teacher: People9.{ public:10.virtual Teacher(){}11.void SayHi(){cout<<"大家好,我是一名教师!\n"; }12.};13.class Student: People14.{15.public:16.void Student(){}17.void SayHi(){ cout<<"大家好,我是一名学生!\n"; }18.};int main(){People *people;Student student;Teacher teacher;int i;do{cout<<"1 教师 2 学生:\n";cout<<"0 退出\n";cin>>i;switch(i){ case 1:people=&teacher;break;case 2:people=&student;break;case 0:exit(0);} people->SayHi();}while(true);return 0;}
查看答案
搜索结果不匹配?点我反馈