#include"Point.h"#include"Rectangle.h"intmain(){
Rectangle rect;//定义Rectangle类的对象
rect.initRectangle(2,3,20,10);//设置矩形的数据
rect.move(3,2);//移动矩形位置
cout <<"The data of rect(x,y,w,h):";
cout << rect.getX()<<","//输出矩形的特征参数<< rect.getY()<<","<< rect.getW()<<","<< rect.getH()<< endl;return0;}
//Rectangle.h#include"Point.h"classRectangle:private Point //派生类定义部分{public://新增公有函数成员voidinitRectangle(float,float,float,float);floatgetX()const;floatgetY()const;voidmove(float,float);floatgetH()const;floatgetW()const;~Rectangle();private://新增私有数据成员float w, h;};
#include"Point.h"void Point::initPoint(float x =0,float y =0){this->x = x;this->y = y;}void Point::move(float offX,float offY){
x = x + offX;
y = y + offY;}
Point::~Point(){
cout <<"Destructing Point...\n";}