标签:int main bsp rectangle ret circle 派生 IV png
1 //纯虚函数的学习 2 //由于纯虚函数的在类中并没有给出函数定义,因此要求其派生类中必须覆盖该纯虚函数,并给出该纯虚函数的函数定义体 3 #include<iostream.h> 4 5 class Shape{ 6 public: 7 virtual void draw()=0; 8 }; 9 10 11 class Rectangle:public Shape{ 12 public: 13 void draw(){ 14 cout<<"绘制矩形"<<endl; 15 } 16 }; 17 18 class Circle:public Shape{ 19 public: 20 void draw(){ 21 cout<<"绘制圆形"<<endl; 22 } 23 }; 24 25 int main(){ 26 Shape *p; 27 p=new Rectangle(); 28 p->draw(); 29 30 p=new Circle(); 31 p->draw(); 32 33 34 return 0; 35 }
标签:int main bsp rectangle ret circle 派生 IV png
原文地址:https://www.cnblogs.com/Tobi/p/9250742.html