Definition of a function
- C + + is a static strongly typed language that, for each function call, checks for the fact that the argument must be the same as the formal parameter type or can be converted to that type.
Parameter passing
- Parameters of a generic non-reference type are initialized by copying the corresponding arguments. Reference parameters are directly associated with the bound object, not a copy of those objects.
- Another use of reference parameters is to return additional results to the keynote function (when a return value is insufficient).
- In love. When a function passes a large object, a reference parameter is used to avoid the copy operation: the formal parameter should be defined as a const reference at this time.
- Note that when you return a reference, you must not return a reference to a local variable. Also, you cannot return a pointer to a local object.
inline functions
- Defining a function as an inline function is to "inline" on each call point in the program to avoid the overhead of function calls.
- Inline functions should be defined in the header file. Its definition can occur more than once, as long as it appears only once in a source file and exactly the same in all files.
Overloaded functions
- A function cannot implement overloading only on the basis of a different return type. Whether a parameter is const is affected only when the reference or pointer is a parameter.
- The overload of the function is determined in three steps: The candidate function, select the feasible function, find the best match.
- To determine the best match, the compiler divides the conversion of the argument type into the corresponding parameter type in descending order: exact matching, matching by type promotion implementation, matching through a standard transformation implementation, and matching by class type conversion.
C + + supplements (iii)--functions