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)
{cout
Int main ()
{Myint MI1;
Cout
}
CodePudding user response:
To add a const, const reference to receive the right values, the amount of temporaryOstream& 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: