#include <iostream>
// 基类(父类)
class Shape {
public:
void setWidth(int w) {
width = w;
}
void setHeight(int h) {
height = h;
}
protected:
int width;
int height;
};
// 派生类(子类)
class Rectangle : public Shape {
public:
int getArea() {
return width * height;
}
};
int main() {
Rectangle rect;
rect.setWidth(5);
rect.setHeight(10);
int area = rect.getArea();
std::cout << "矩形的面积为:" << area << std::endl;
return 0;
}