继承
继承 一.继承的三大类 公有继承 私有继承 保护继承 继承方式规定了如何访问从基类继承的成员。 继承关键字为:public,protected和private。如果不显示地给出继承方式关键字,系统的默认值就认为是私有继承。 类的继承方式指定了派生类成员以及类外对象对于从基类继承来的成员的访问权限。 二.公有继承 例子: #include<iostream> using namespace std; class Point { public: void initPoint(float x = 0, float y = 0) { this->x = x; this->y = y; } void move(float offX, float offY) { x += offX; y += offY; } float getX() { return x; } float getY() { return y; } private: float x, y; }; class Rectangle :public Point { private: float w, h; public: void initRectangle(float x, float y, float w, float h) { initPoint(x, y); this->w = w; this->h = h; } float