#include <iostream>using namespacestd; classcmyint{Private: intvalue; Public: Cmyint (intx): Value (x) {} cmyint (): Value (0){} //++iCmyint &operator++() {Value++; return* This; } //i++Cmyintoperator++(int) {Cmyint temp= * This; ++(* This); returntemp; } cmyint&operator=(ConstCmyint &B) { if( This! = &b) This->value =B.value; return* This; } intgetInt () {returnvalue; } //operator Int () const{//overlapping with implicit conversions above, ambiguity will occur in mixed operations, and if you need to go int, you can define an interface, i.e. Getint ()//return value; //}friend Ostream&operator<< (Ostream &,ConstCmyint & ); Friend Cmyintoperator+ (ConstCmyint & A,ConstCmyint &B);};o Stream&operator<< (Ostream & out,ConstCmyint &Myint) { out<<Myint.value; return out;} Cmyintoperator+ (ConstCmyint & A,ConstCmyint &B) { returnCmyint (A.value +b.value);} intMain () {Cmyint Myint (0), Inta (2), INTB (2); intx, y; cout<< (myint++) + (myint++) <<endl;//Print 1cout << Myint <<endl;//Print 2
What is the difference between comparison and built-in Post + +intA=0; cout<< (A + + a++) <<endl;//Print 0cout << a <<endl;//Print 2x=Myint.getint (); Myint= Inta + INTB +x; cout<< Myint <<endl;//6//Y=myint;//illegalY=myint.getint ();//Legal;cout << y <<endl;//Print 6Myint= y = (inta + x + intb). GetInt ();//Continuous Assignmentcout << Myint <<" "<< y <<Endl;}
Simple implementation of Myint