See C + + (default template, special template) with Assembly vision

Source: Internet
Author: User
Tags function definition

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

The default function is a basic feature of C + +. The default function definition is simpler, that is, for one input parameter of a function or several input parameters, if you do not have a specific value, we will replace it with the default data. If you use your own data during the call, the default data will be overwritten by our own defined data. The following is an example of a default function:

View plain int Add (int m, int n = ten) {return m + N; What's the difference if it's called?

View Plain 262:      int p = add (2);   00401488    push        0Ah   0040148a   push         2   0040148c   call          @ILT +15 (add)   (00401014)    00401491   add          esp,8   00401494   mov          dword ptr [ebp-4],eax   263:       p = add (3, 4);   00401497   push         4   00401499   push         3   0040149b   call         @ILT +15 (add)   (00401014)   004014a0   add         esp,8    004014a3   mov         dword ptr [ ebp-4],eax        You can see from the above code, if you enter a separate data 2, then the compiler to help us enter the default 10, if the lost data is 3, 4, then the compiler will use 4 instead of the default data 10. So, the compiler helps us do the middle of the substitution and judgment work. So what happens when we go back to the default template type we're talking about today? We can write an example:

View Plain Template <typename type1, typename type2 = int> class Data {type2 value; Public

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.