Erro ao compilar programa – sobrecarga operador
:o
O programa abaixo apresentou erro de compilação após eu inserir um construtor. Vejam:
#include <iostream>
#include <cstdlib>
using namespace std;
class Sobrecarga
{
private:
double x,y,n;
public:
Sobrecarga(double num){n = num;};
//Operadores unários
Sobrecarga operator++(int);
Sobrecarga operator++();
Sobrecarga operator--(int);
Sobrecarga operator--();//Operador binnario
Sobrecarga operator+(Sobrecarga s1);
};
Sobrecarga Sobrecarga::operator++()
{
this->x++;
this->y++;
return *this;
}
Sobrecarga Sobrecarga::operator++(int)
{
this->x++;
this->y++;
return *this;
}
Sobrecarga Sobrecarga::operator--(int)
{
this->x--;
this->y--;
return *this;
}
Sobrecarga Sobrecarga::operator--()
{
this->x--;
this->y--;
return *this;
}Sobrecarga Sobrecarga::operator+(Sobrecarga s1)
{
Sobrecarga temp;
temp.x=x + s1.x;
temp.y=y + s1.y;
return temp;
}
int main()
{
cout << "sobrecarga de operadores " << endl;
Sobrecarga a(6);
a++;
return 0;
}
Erros:
Sobrecarga_operador.cpp:51:13: error: no matching function for call to 'Sobrecarga::Sobrecarga()'Sobrecarga_operador.cpp:51:13: note: candidates are:
Sobrecarga_operador.cpp:12:2: note: Sobrecarga::Sobrecarga(double)
Sobrecarga_operador.cpp:12:2: note: candidate expects 1 argument, 0 provided
Sobrecarga_operador.cpp:6:7: note: Sobrecarga::Sobrecarga(const Sobrecarga&)
Sobrecarga_operador.cpp:6:7: note: candidate expects 1 argument, 0 provided
Como resolver estes problemas ?
Obrigado
Discussão (13)
Carregando comentários...