Function Declarations and Definitions
函数声明和定义
Return type on the same line as function name, parameters on the same line if they fit. Wrap parameter lists which do not fit on a single line as you would wrap arguments in a function call.
函数返回类型和函数名要在同一行,如果合适函数参数也要在同一行,封装参数列表不适合在一个行上打包
Functions look like this:
函数像这样:
ReturnType ClassName::FunctionName(Type par_name1, Type par_name2) {
DoSomething();
...
}
If you have too much text to fit on one line:
如果你有太多的需要在同一行:
ReturnType ClassName::ReallyLongFunctionName(Type par_name1, Type par_name2,
Type par_name3) {
DoSomething();
...
}
or if you cannot fit even the first parameter:
或者如果第一个参数第一行都放不下:
ReturnType LongClassName::ReallyReallyReallyLongFunctionName(
Type par_name1, // 4 space indent
Type par_name2,
Type par_name3) {
DoSomething(); // 2 space indent
...
}
Some points to note:
需要注意的点:
1、Choose good parameter names.
选择一个好的参数名字
2、A parameter name may be omitted only if the parameter is not used in the function's definition.
只有当一个参数在函数定义中没有被使用时,参数的名字才可以被省略。
3、If you cannot fit the return type and the function name on a single line, break between them.
如果你不能使函数返回类型和函数名在同一行也是可行的
4、If you break after the return type of a function declaration or definition, do not indent.
如果函数返回类型和函数名不在同一行,不要缩进
5、The open parenthesis is always on the same line as the function name.
左圆括号:(总是和函数名在同一行
6、There is never a space between the function name and the open parenthesis.
左圆括号:(和函数名之间永远不要有空格
7、There is never a space between the parentheses and the parameters.
参数和括号之间永远不要有空格
8、The open curly brace is always on the end of the last line of the function declaration, not the start of the next line.
左大括号:{总是在函数声明的最后一行 不要重开一个新行
9、The close curly brace is either on the last line by itself or on the same line as the open curly brace.
右大括号:}可以自己独自一行或者和左大括号:{在同一行
10、There should be a space between the close parenthesis and the open curly brace.
右圆括号:)和左大括号:{之间必须要有空格
11、All parameters should be aligned if possible.
所有参数应该尽可能对齐
12、Default indentation is 2 spaces.
默认缩进是两个空格
13、Wrapped parameters have a 4 space indent.
封装的参数具有4个空间缩进