Ⅲ function

First, the function call execution process

1.fun (3.14) // The actual parameter is implicitly converted to integer 3 in the function

2. The name has a scope, the object has a life cycle → the function body is a block, and there is a new scope in this block → the formal parameters & other definitions defined in this scope are local variables, only in Appears only when the function is executed

3. Local static objects

From the execution of this statement, it does not disappear until the end of the program, even if the function where it disappears does not matter (powerful!)

 

 

4. Function declaration

Named, no content, declared in header file, defined in source file

5. Parameter passing

Each time the function is called, the formal parameters are recreated and initialized with the actual arguments passed in

When the parameter type → reference parameter is the argument of; otherwise, the argument is a value assigned to the parameter

When using references, use common references as much as possible : the use of references makes the formal and actual parameters bound together, and the actual parameters can be easily changed, which is not good

 

Second, the inline function

 

 

 

3. Functions with default parameters

If the actual parameter is given by the call, the formal parameter value is used, otherwise the default parameter value is called

 

 

When declaring: Cannot be assigned half, not half

When defining: with int a = 1 in the declaration, it is used directly when it is defined, no longer defined; it must be defined from right to left, the leftmost can be undefined, but it cannot be directly fun ();

When in use: You can't leave a few in the middle and continue to assign values;

 

Four, function overloading

1. Overload: The same thing corresponds to different operation modes

 

 2. Implementation mechanism: Although the name is the same, the number & type of the following parameters are different, and the compiler distinguishes according to that (advanced than C ~~)

3. Note

 

 

Five, function template

Simplify and simplify, then simplify \ ( ̄︶ ̄ * \))

 

 

 

 1. If you define an overloaded function at the same time, the overloaded function will be used first. If you cannot find an exact match, then use the function template

 

Six, system functions

 

Guess you like

Origin www.cnblogs.com/syzyaa/p/12677928.html