2
Hello, I’m doing an exercise consisting of the following statement:
Sorry to put a print, but I could not select the text and it would be unnecessary to type everything here.
Finally, I made the class and implemented the overload of operators +, -, * and /, but I’m not able to do the part of operators << and >>, used in Cin and Cout.
#include <iostream>
using namespace std;
class MeuInt{
public:
MeuInt(int i=0);
int operator+(int);
int operator-(int);
int operator*(int);
int operator*(MeuInt);
int operator/(int);
friend ostream &operator>>(ostream&, const MeuInt&);
friend istream &operator>>(istream&, MeuInt&);
int getInteiro();
void setInteiro(int);
private:
int inteiro;
};
MeuInt::MeuInt(int i){
inteiro = 1;
}
int MeuInt::operator+(int x){
inteiro = x + inteiro;
return inteiro;
}
int MeuInt::operator-(int x){
inteiro = x - inteiro;
return inteiro;
}
int MeuInt::operator*(int x){
inteiro = x * inteiro;
return inteiro;
}
int MeuInt::operator*(MeuInt x){
inteiro = x * inteiro;
return inteiro;
}
int MeuInt::operator/(int x){
inteiro = x / inteiro;
return inteiro;
}
int MeuInt::getInteiro(){
return inteiro;
}
void MeuInt::setInteiro(int x){
inteiro = x;
}
MeuInt calcDelta(MeuInt a, MeuInt b, MeuInt c){
MeuInt delta = b*b - a * c * 4;
return delta;
}
ostream &operator>>(ostream& saida, const MeuInt& meuint){
output << meuint.getInteiro();
return output;
}
istream &operator>>(istream& entrada, MeuInt& meuint){
}
int main(int argc, char** argv) {
MeuInt inteiro1(10);
MeuInt A, B, C;
int c = inteiro1 + 1;
cout << "inteiro1 + 1: ";
cout << c << endl;
cout << "Entre com as variáveis: " << endl;
cout << "A: ";
cin >> A;
cout << "B: ";
cin >> B;
cout << "C: ";
cin >> C;
return 0;
}
With the above code, the IDE is returning the following errors:
- In function 'Std::ostream & Operator>>(Std::ostream&, const Meuint&)':
- 'output' not declared previously
- Passing 'const Meuint' as 'this' argument from 'int Meuint::getInteiro()' discards qualifiers
- In function 'Std::istream & Operator>>(Std::istream&, Meuint&)':
- This function is not void and no return expression has been found
Thank you in advance.
have you ever tried to fix errors ? at least the first one is self-explanatory: "output' has not been declared previously"...
– zentrunix
Yes, this was obvious and I ended up putting it without realizing it. I solved the errors and put the code in a reply. Thank you.
– Leila