How to use C++ function types and overloaded functions
This article introduces the knowledge of "how to use C++ function types and overloaded functions". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. First of all, for the overloaded function, it is clear that the return type of the function can not determine the category of the overloaded function, that is, int F (int, int); / / A function that returns int type void F (int, int); / / A function with no return value has the same formal parameter list and different return value types, but the two do not constitute overloaded function 2. Note the default values in the formal parameter list, which may be ambiguous when using overloaded functions with default parameters. For example: int a = 0 politics int Max (int,int); int Max (int,int,int = 0); / / the call to Max (3 Magi 5) will report an error a = Max (3 Magi 5); / / error
In addition, the default parameters should be specified when the function name is first given, usually in the function prototype. If the default parameters have been specified in the function prototype, the function definition cannot be repeated.
Question:
I saw such a problem in a question, which, in a nutshell, allows you to call an overloaded function passed by a value and an overloaded function passed by a reference.
# includeusing namespace std;void F (int & a, int & b) {a = a + b; cout