Help with this error matching functions in class

Hi, i can't fix this code, 'cause i dont know reason be giving this error. Help please!

My code:

#include <iostream>

class Retangulo{
public:
Retangulo();
Retangulo(int);
Retangulo operator + (const Retangulo &);
void setValores(int, int);
int area(){return (largura*altura);}
private:
int largura, altura;
};

Retangulo Retangulo::operator + (const Retangulo& direita) {
Retangulo temp(altura + direita.altura, largura + direita.largura);
return temp;
}

Retangulo::Retangulo(int x){
altura = x;
largura = x;
}

Retangulo::Retangulo() {
largura = 5;
altura = 5;
}

void Retangulo::setValores(int x, int y){
altura = x;
largura = y;
}

using namespace std;

int main()
{
Retangulo r1(3, 4);
Retangulo r2(4,5);
Retangulo r3 = r1 + r2;

cout << "Area da bagaca eh: " << r3.area() << endl;

return 0;
}
Last edited on
What error? Please wrap your code in Code Blocks -- you will find them under Format:
Error this part:
Retangulo Retangulo::operator + (const Retangulo& direita) {
Retangulo temp(altura + direita.altura, largura + direita.largura);
return temp;
}

error: no matching function for call to 'Retangulo::Retangulo(int, int)'|
Last edited on
1. Please use code tags to make your code readable:

http://www.cplusplus.com/articles/z13hAqkS/

2. You haven't declared a constructor that takes two ints:

1
2
3
public:
Retangulo();
Retangulo(int);

but you're trying to call a constructor that takes two ints:

Retangulo temp(altura + direita.altura, largura + direita.largura);
Last edited on
Topic archived. No new replies allowed.