C ++ Primer Chapter 8 summarizes the relevant issues and

What 1.C ++ inline functions are?

1. inline speed slightly faster than the conventional function, it is because of c ++ space for time.
2. If the code execution is longer than the time handler to call the mechanism, so this time we can use inline functions.
3. inline function is not recursive.
4. inline function for small scale operation, can not be too long.
The inline function is generally written in the beginning of the file, and the code itself is not high, it is not necessary prototypes.

2. Create a reference variable Precautions

It must be initialized when declaring reference variables.

int * const pr = &rats; 	//ok

int rat;
int &rodent;
rodents = rat;		//No,you can't do this

3. The function parameter as a reference

Passed by value leads to the calling program using the copy of the value of the function is called when passing references, means that the function can use the original data.

4. What is the value left?

Left parameter data objects can be referenced, for example: variables, array elements, structure members, and references are dereferenced pointer value left.
It can be understood as an expression of the equal sign = left part, then the value of the corresponding non-left is the right = literal and contains a number of expressions.

5. Why should use const as possible

1. Use programming errors const avoid inadvertent modification of data.
2. const const and enable functions to handle non-const argument, otherwise the data can only accept non-const.
3. Use the const reference function to generate and use temporary variables correctly.

6. Why use a reference parameter?

1. The programmer can modify a data object in the function call.
2 instead of the entire data object referenced by transfer, can be increased running speed.

7. What are the default parameters?

E.g:

char * left(const * str,int n = 1);

The default setting value for n is 1, and when the function call, you can not set n.
For a list of function parameters, the default value must be added from right to left, which means that to set a default value for a parameter, you must provide default values for all parameters it right.

8. function template

1. Normal template prototype:

template<typeName T>
void Swap(T &a,T &b);

2. Explicit embodied

template<> void Swap<job>(job &a,job &b)	//<job>可以省略
发布了17 篇原创文章 · 获赞 2 · 访问量 214

Guess you like

Origin blog.csdn.net/weixin_42709632/article/details/103949417