Pku c ++ Program Design Study Notes
1.7 inline and overloaded functions
Inline functions: function calls have time overhead. If a function has only a few statements, the execution is very fast, and the function is repeatedly executed many times, the overhead produced by calling the function will appear relatively large.
To reduce the overhead of function calls, the inline function mechanism is introduced. When the compiler processes a call statement for an inline function, it inserts the code of the entire function into the call statement without generating a function call statement.
Overload function: one or more functions with the same name, but the number or type of parameters are different. This is called a function overload. The compiler determines which function to call based on the number and type of real parameters in the call statement.
(1) int Max (double f1, double f2) {} (2) int Max (int n1, int n2) {} (3) int Max (int n1, int n2, int n3) {} Max (3.4, 2.5); // call (1) Max (); // call (2) Max (, 3 ); // call (3) Max (3, 2.4); // error, ambiguity, which can be called after type conversion (1) or after type conversion (2)
1.8 default function parameters
In C ++, when defining a function, several consecutive parameters on the rightmost side can have default values. When calling a function, if no parameter is specified at the corresponding position, the parameter is the default value.
Function parameters can be defaulted to improve program scalability. That is to say, if you want to add new parameters to a function, but the statements that call the function do not need to use new parameters, in order to avoid modifying the original function call statements, you can use the default parameter.
2.1 object-oriented programming methods
Four basic object-oriented concepts: abstraction, encapsulation, inheritance, and Polymorphism
Abstract: sums up the common attributes of a type of objective things to form a data structure. Summarize the behaviors and operations that can be performed by such things to form functions that can be used to operate on specific data structures.
Inheritance: binds data structures and algorithms to form classes.