Home > Back-end >  C overloading the decrement operator
C overloading the decrement operator

Time:10-04

Overloading the decrement operator
My code is as follows, check the CSDN said this error as input and output stream to write wrong, I checked the is indeed the output stream ostream, single write overloaded left shift operator results correctly, lead the decrement is also correct, suspect that the fault in the buy inside the decrement operator, but check the along while to find errors, seek help from a great god
#include
using namespace std;
The class Myint
{private:
int num;
Public:
Friend ostream& Operator<(ostream& Cout, Myint & amp; MI1);
Myint ()
{num=10; }
//reload the decrement operator
Myint& Operator - ()//lead the decrement operator
{- num;
Return * this; }
Rear Myint operator - (int),//the decrement operator (parentheses) before and after add int in order to distinguish between
{Myint temp=* this;
- num;
Return temp. }
};
//reloading the left shift operator
Ostream& Operator<(ostream & amp; Cout, Myint & amp; MI1)
{coutReturn cout. }
Int main ()
{Myint MI1;
CoutCout<- MI1 & lt; Coutreturn 0;
}

CodePudding user response:

To add a const, const reference to receive the right values, the amount of temporary

Ostream& Operator<(ostream & amp; Cout const Myint & amp; MI1)

MI1 - returns the right values

CodePudding user response:

Friend ostream& Operator<(ostream& Out, const Myint & amp; MI1);

CodePudding user response:

reference 1st floor SDGHCHJ response:
to add const, const reference to receive the right values, temporary amount

Ostream& Operator<(ostream & amp; Cout const Myint & amp; MI1)

MI1 - returns the right values

Understand, modify the already compiled successfully, thank you for your bosses
  • Related