Why use function overloading
First attach my stand known results .
1, to reduce the complexity of the user.
2, this reduces the number of function names, to avoid the contamination of the name space, for readability a great advantage.
Overloads function is a special case, for ease of use, C ++ statements to allow several functions with the same name in the function similar to the same range, but the same name as a function of these parameters form (refer to the number of parameters, the type or order) must be different , that perform different functions with the same arithmetic operator. This is overloaded functions. Overloaded function used to implement the functions and the like are different types of data processing problems.
A role: reducing complexity for the user
这点是很好理解的,为了方便开发,若具有相同功能但针对类型不同的函数过多,就会导致编程人员存在过多的时空花销。但是针对用户,我就也不太清楚了。
The role of two
列出一下几个求和函数:
sum (int a, int b) // do not write the return type and returns an int
Double SUM (Double A, Double b)
float SUM (floata, float b, float c)
for the following statement is different calling
int x = sum (2,8);
; a float Y = SUM (5.6,11.1)
a float Z = SUM (a float (X), Y,. 5);
passing the said requirements of overloaded functions :
when the overloaded function call, the compiler calls the appropriate function corresponding to the type of argument. The matching process is performed as follows:
(1) If there is an exact match parameters (number of parameters, exactly the same type) function, the function is called;
(2) through the internal parameters to match the type of conversion, the function call;
(3) parameters sought by matching user-defined type conversion.
When defining the number of overloaded functions must ensure that different types or parameters, only return values of different types is not acceptable.