Yo Udomkarn Yo Udomkarn - 1 year ago 44
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
double width;
double height;
Rectangle(double width, double height);
double area();
double circumference();
double getWidth();
double getHeight();

class SquareRectangle:public Rectangle//inheritance{
double side;
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

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download