C++教程:C++抽象类与纯虚函数

2020-01-06 12:29:04丽君

#include "undergraduate.h"
#include "pupil.h"
using namespace std;
int main()
{
   Undergraduate s1;
   /*student s2;//此时创建学生对象将会出现编译错误*/
   Pupil s3;
   student *sp=&s1;
   s1.set("Tom",21,178,60);
   sp->study();
   sp=&s3;
   s3.set("Mike",8,148,45);
   sp->study();
   return 0;
}
运行结果:
Constructing a student without parameter...
Constructing a student without parameter...