#include <iostream>
#include <cmath>
using namespace std;
class Rectangle{ //class
private:
double width;
double height;
public:
Rectangle(double width, double height);
double area();
double circumference();
double getWidth();
double getHeight();
};
class SquareRectangle:public Rectangle//inheritance{
private:
double side;
public:
SquareRectangle(double side);
double getSide();
};
Rectangle::Rectangle(double width, double height){
this->width = width;
this->height = height;
}
double Rectangle::area(){
return (getWidth()*getHeight());
}
double Rectangle::circumference(){
return ((getWidth()*2)+(getHeight()*2));
}
double Rectangle::getWidth(){
return width;
}
double Rectangle:: getHeight(){
return height;
}
SquareRectangle::SquareRectangle(double side){
this->side = side;
}
double SquareRectangle::getSide(){
return side;
}
并且在此图片中可以看到此错误 Error
感谢这里的所有帮助
答案 0 :(得分:2)
SquareRectangle 的构造函数需要调用其父类 Rectangle 的构造函数。构造函数可以这样编码:
SquareRectangle::SquareRectangle(double side)
: Rectangle(side, side) {
this->side = side;
}