Yo Udomkarn Yo Udomkarn - 5 months ago 18
C++ Question

[c++]no matching function to call, expect 2 argument 0provide

Got some error with this coding one rectangle class, one inheritance



-----------------------------------------------------------------------------



#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

Answer Source

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;
}