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

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

#include <iostream>
using namespace std;
class student//因为存在纯虚函数study,student类自动变成了抽象类
{
   public:
   student(char *n,int a,int h,int w);
   student();
   void set(char *n,int a,int h,int w);
   char * sname();
   int sage();
   int sheight();
   int sweight();
   virtual void study()=0;//声明study为纯虚函数
   protected:
   char name[10];
   int age;
   int height;
   int weight;
};