See C + + (arithmetic overload) with Assembly vision

Source: Internet
Author: User
Tags arithmetic

Turn from: http://blog.csdn.net/feixiaoxing/article/details/6785924

An arithmetic overload is an attribute of a class, but each person uses a different method. Good use, but if not the correct use, it will be endless.

(1) Introduction of simple arithmetic characters

So what is an arithmetic overload? We can give an example. In general, when we define two variables of type int, we can add, subtract, multiply, and divide the two types, and compare judgment, print, array operation, * operation, and so on. So what should we do if we want to define our own classes with such attributes? Of course, the arithmetic character overload is necessary. First, we do a definition of the basic class:

View plain class desk   {   public:       int price;           desk (int value):p rice (value)  {}        ~desk ()  {}       desk& operator+=  (desk&  D) {           this->price += d.price;            return *this;        }  };        below, you can use an example function to illustrate the method used:

View Plain 74:       desk n (5);   0040126d    push        5   0040126f   lea          ecx,[ebp-10h]   00401272   call          @ILT +0 (desk::d Esk)   (00401005)    00401277    mov         dword ptr [ebp-4],0   75:        desk m (;  ) 0040127e   push         0Ah   00401280   lea          ecx,[ebp-14h]   00401283   call          @ILT +0 (desk::d Esk)   (00401005)   

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.