function overloading
function overloading is defined as a function overload in the same scope, if the function has the same name and only the formal parameter list is different. Note A function overload cannot be overloaded based on a different return value type.
Note that the "formal parameter list" in the function overload is different from the nature, so do not be confused by some appearances. The main function cannot be overloaded.
The following three sets of definitions are essentially the same, not overloaded:
1) int sum (int &a); and int sum (int &);
2) int sum (int a) and int sum (const int a);
3) typedef int DD;
int sum (int a); and int sum (DD a);
The second example is the equivalent of whether a parameter is const for a non-reference parameter. However, when using reference parameters, there is no const is different. When you use pointer parameters, pointers to const objects and functions that point to pointers to non-const objects are different.
* Here's a more disgusting question, based on the const overload.
There is such an overload in the class that it is legal.
Class A {
int function ();
int function () const;
};
As you can see in Class A, function functions are overloaded and legal. And when called, only the const object of Class A can call a const version of a function, and not a const object may call any one, usually a non-const object calling a function that is not a const version.
The reason: According to the definition of function overloading, the function name is the same and the formal parameter list has essentially different functions called overloading. In a class, because of the existence of the implied this parameter, the const version of the function function causes the type of the this pointer that is the formal parameter to be a pointer to a const object, rather than a const version that makes the this pointer of the formal parameter the normal version of the pointer. Here is the nature of the overloads that occur. The overloaded function selects the const version of the member function for the Const object invocation, while the normal object invocation selects the non-const version of the member function during the best bet.
(Note: this pointer is a const pointer, the address cannot be changed, but it can change the object or variable it points to)
C + + learning function overloading, const-based overloading