About function overloading __ functions

Source: Internet
Author: User

A. The conditions that make up a function overload are as follows:

1. The function name is the same.

2. The formal parameters of these functions of the same name (the number, type, or order of the parameters) must be different, that is, the parameter list is different.

3. The return value type does not form an overloaded function.

Two. The matching principle of overloaded function:

1, the strict match, find after the call.

2, did not find a strict matching function, but can be implicitly converted to find the appropriate overloaded functions.

Cases:

1. Parameter types are not the same

void print (int a)

{

printf ("Void print (int a) \ n");

}

void print (String a)

{

printf ("Void print (string a) \ n");

}

2. Different number of parameters (1)

void print (int A, string b);

3. Different parameter order (more 2)

void print (string a, int b);

In order to estimate which overloaded function is best suited, you need to follow the following rules: exact match : parameter matching without conversion, or just trivial conversions, such as group name to pointer, function name to pointer to function, t to const; Promotion Match : That is, integer elevation (such as bool to int, char to int, short to int), float to double matches with a standard conversion : int to double, double to int, double to long double, derived* to Base*, t* to void*, int to unsigned int; use user-defined matches ; ellipses matching : Similar to printf ellipsis parameters

The same scope is also a qualification in the definition of a function overload, which, if not a scope, is not a function overload, as in the following code:

void f (int);

void g ()
{
        void F (double);
        f (1); This is called F (double) instead of F (int)
}
That is, the inner-scope function hides the outer-named function. The member function of the same derived class hides the same function as the base class. This is well understood, as is the case for variable access, such as a variable with the same name in a function body to access the global to be qualified with "::".

This article is just a rough basic introduction to learn more please refer to the great god http://www.cnblogs.com/skynet/archive/2010/09/05/1818636.html

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.