C ++ programming philosophy-function overloading and default parameters

Source: Internet
Author: User

Function overloading means that different operations are distinguished by different parameters.

Function overload only requires different parameters. The compiler splits function names, ranges, and parameters to generate internal names for the linker.

 

The significance of default parameters lies in: 1. Simplifying the setting of fixed parameter values to facilitate function calls; 2. Making it easier to modify function definitions in the future.

The default value is defined when the parameter is declared. The default value cannot be written when the parameter is defined, which is the same as that of a normal function. Example: void fun (INT Param, Int = 0, float = 1.1)

The default parameter cannot be used as a flag to determine which function to execute. This is the basic principle. In this case, as long as the function can be used, the function should be decomposed into two or more overloaded functions.

◆ The default parameter does not have an identifier for the declared parameter. This syntax allows you to use a parameter as a placeholder instead of using it. The purpose is that we can modify the function definition in the future without modifying the function call.

◆ An important application of the default parameter is that the new parameter can use the default parameter to ensure that allCodeNo trouble.

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.