C++ object-oriented functions

[Function]
Function call:
value transfer call: the formal parameter changes, the actual parameter is not affected, and the data is transferred in one direction.

Address transfer: When the formal parameter is an array or pointer, the change of the formal parameter directly affects the actual parameter.

Reference call: The formal parameter is equivalent to an alias of the actual parameter. The call effect is the same as the address transfer, which realizes two-way data transfer. On the basis of value transfer, you only need to add the symbol "&" before the formal parameter.

Data transfer: 1. Transfer from actual parameters to formal parameters. 2. Transmission address: The formal parameter changes, the actual parameter also changes, and the two-way transmission of data is realized.

Function with default parameter value: When defining the function parameter, you can give the parameter a default parameter value. If the function caller does not pass data (value, address) to the formal parameter, the formal parameter takes the default (default) value. A parameter with a default value must be placed to the right of a parameter without a default value.

Function overloading Overloading
polymorphism (static polymorphism)
must have the same function names for several functions, and the number of formal parameters or types of formal parameters are different.
The function name must be the same and has nothing to do with the formal parameter name. As for the number and type of the formal parameter, it has nothing to do with the return value type of the function.

Inline function: When defining a function, you can add the inline keyword to the function header to declare this function as an inline function. The function call does not jump to the calling scene during the running stage, but directly replaces the calling statement with the corresponding executed function code in the compilation stage.

Advantages: Improve the efficiency of program operation and save the time and space for memory blocks to jump to each other caused by function calls during operation.

Note: The compiler defaults short, concise functions to inline functions. The function can be specified by the keyword inline, but the compiler may not recognize it. For example, the function code is cumbersome, such as calling a function recursively. Even if inline is added, the compiler will not treat this function as an inline function.

Author: SKYBQL
All Rights Reserved
2020/6/29

Guess you like

Origin blog.csdn.net/qq_45823731/article/details/107029097