Focus:
1. Three function-related language features: default arguments, inline functions, and constexpr functions.
2. Default arguments: Some functions have a formal parameter, and they are given the same value in many calls to the function.
3. Once a parameter has been given a default value, the parameter after it must have a default value.
4. If you want to use the default parameter, simply omit the argument when calling the function.
Tip:Window = Screen (,, '? ' );// error: Only the trailing arguments can be omitted!
5. For a function declaration, it is customary to place it in the header file, where a parameter can only be given one default argument at a given scope.
Note: In general, you should specify the default argument in the function declaration and place the declaration in the appropriate header file.
6. One-time function call: To save the register before the call and restore it on return, you may need to copy the argument and the program will move on to a new location to continue execution.
7. Inline function (inline): Eliminates overhead when the function is running.
Note: The inline description is just a request made by the compiler, and the compiler can choose to ignore the request.
8. The inline mechanism is used to optimize functions that are small, process-direct, and frequently called.
9.Constexpr function: Refers to a function that can be used for constant expressions.
Define the constexpr function: The return type of the function and the type of all formal parameters are literal types (arithmetic type: integer and float, reference and pointer,string not included),
the function body must have only one return statement.
10. To be able to unfold at any time during the compilation process, theconstexpr function is implicitly specified as an inline function.
The 11.constexpr function does not necessarily return a constant expression.
12. For a given inline function or constexpr function, its multiple definitions must be exactly the same, based on which the inline function and the constexpr function are usually defined in the header file.
13. When the application is written to prepare for release, it is necessary to block out the debug code, which uses two preprocessing functions:assert and ndebug.
14.Assert is a preprocessing macro, which is actually a preprocessing variable, a behavior type and an inline function:Assert (expr); when Expr to be 0 , assert Output Information termination program, Expr Non- 0 , assert don't do anything.
15. Preprocessing names have preprocessor non-compiler management.
16. As with preprocessing variables, the macro name is unique within the program.
the behavior of 17.Assert relies on the state of a preprocessing variable named ndebug . If ndebugis defined, assert does nothing, and if no ndebugis defined, the assert a run-time check is performed.
Special-Purpose language features: default arguments, inline functions, and constexpr functions, debugging Help