Simple implementation of Myint

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.