Reputation: 43
#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;
}
and got this error as you can see in this picture Error
appreciate all the help here
Upvotes: 3
Views: 51
Reputation: 382
The constructor for SquareRectangle needs to invoke the constructor of its parent class Rectangle. The constructor can be coded-up like so:
SquareRectangle::SquareRectangle(double side)
: Rectangle(side, side) {
this->side = side;
}
Upvotes: 3