1. Concept of function overloading
function overloading means that a function can have the same name as other functions in the same scope, but the parameter types, number of arguments, return values, and function functions of the same name functions can be completely different.
I self-study, the textbook may be a bit old, there are problems to ask you correct!!! Thank you!!!
2 . function Overloading Considerations
- A function overload cannot be just a function that has a different return value, at least in the number, type, or order of formal parameters.
- You should make the overloaded functions you use the same functionality. If you let overloaded functions do different things, it is a bad programming style, which destroys the readability of the program.
Example: Define and test overloaded functions.
1#include <iostream>2 using namespacestd;3 4 intAbsoluteintx)5 {6 returnx<0?-x:x;7 }8 9 DoubleAbsoluteDoublex)Ten { One returnx<0?-x:x; A } - - intMinintXinty) the { - returnX<y?x:y; - } - + intMinintXintYintz) - { + returnX<y? (x<z?x:z):(y<z?y:z); A } at - intMain () - { - intA =3; - intb =-8; - intc =6; in DoubleD =-5.23; -cout << min (b) <<Endl; tocout << min (a,b,c) <<Endl; +cout << Absolute (a) <<Endl; -cout << Absolute (b) <<Endl; thecout << Absolute (d) <<Endl; * return 0; $ }Panax Notoginseng - //Rookie, please criticize advice, code writing habits and norms and so on!!! Thank you!!!
I self-study, the textbook may be a bit old, there are problems to ask you correct!!! Thank you!!!
C + + function overloading