1. Write Functions
Declare before calling
2. Call a function
Function parameter value passing includes value passing reference passing pointer passing
3. The function provides default parameters.
Void fun (vector <int> & VEC, ofstream * ofil = 0)
The default value starts from the right side. If a function parameter has a default value, all its right parameters have a default value.
Raise the visibility. The default value is placed at the function declaration, not the definition.
4. Use a local static object
Void fun {
...
Static vector <int> VEC;
...
}
Defining static objects outside a function is an adventure to save the communication problem between functions. It will disrupt the independence between different functions and make them hard to understand.
5. inline functions
The Inline Function indicates that the compiler expands the function content on each function call point. (The compiler replaces the call operations of functions with one-to-one copy of the function code to improve efficiency.) it can be understood as a Java static function.
6. Overload Functions
Different parameters (parameter quantity, parameter type) have the same name
7. template Functions
Template <typename elemtype>
Void fun (vector <elemtype> vect ){
}
8. function pointer pointers to Functions
Const vector <int> * (* fun_ptr) (INT size );
9. header files)
Extension. h standard library exceptions
Function Definition and Declaration
Only one copy can have multiple declarations
The inline function is defined in the header file.
Objects modified by extern (except const object) are as follows:
Const int seq_cnt = 6;
Externconst vector <int> * (* seq_array [swq_cnt]) (INT); // non-const object is a pointer
Include
Include "numseq. H" header file provided by the user
Include <vector> standard header file
2. process-oriented programming