创作人QQ:851301776,邮箱:[email protected],欢迎大家一起技术交流,本博客主要是自己学习的心得体会,只为每天进步一点点!
个人座右铭:
1.没有横空出世,只要厚积一定发。
2.你可以学历不高,你可以不上学,但你不能不学习
一、多态(Polymorphic)
#include <iostream>
using namespace std;
class Shape{//图形基类
public:
Shape(int x=0,int y=0):m_x(x),m_y(y){}
virtual void draw(void){//虚函数
cout << "绘制图形:" << m_x << ','
<< m_y << endl;
}
protected:
int m_x;//位置坐标
int m_y;
};
class Rect:public Shape{//矩形子类
public:
Rect(int x,int y,int w,int h)
:Shape(x,y),m_w(w),m_h(h){}
void draw(void){//也是虚函数
cout << "绘制矩形:" << m_x << ',' <<
m_y << ',' << m_w << ',' << m_h
<< endl;
}
private:
int m_w;//宽
int m_h;//高
};
class Cir