修复格式及部分缩进
This commit is contained in:
72
编码规范.md
72
编码规范.md
@ -17,8 +17,8 @@
|
||||
|
||||
### 缩进
|
||||
|
||||
* 采用4个空格
|
||||
* 空格,不要用TAB!
|
||||
- 采用4个空格
|
||||
- 空格,不要用TAB!
|
||||
|
||||
### 变量声明
|
||||
|
||||
@ -106,6 +106,7 @@
|
||||
```
|
||||
|
||||
- 例外:函数定义和类定义中,左大括号总是单独占一行:
|
||||
|
||||
``` c++
|
||||
static void foo(int g)
|
||||
{
|
||||
@ -119,21 +120,21 @@
|
||||
- 控制语句的body中只有一行时不使用大括号
|
||||
|
||||
``` c++
|
||||
// 错误示例
|
||||
if (address.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
// 错误示例
|
||||
if (address.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; +''i) {
|
||||
qDebug("%i", i);
|
||||
}
|
||||
for (int i = 0; i < 10; +''i) {
|
||||
qDebug("%i", i);
|
||||
}
|
||||
|
||||
// 正确
|
||||
if (address.isEmpty())
|
||||
return false;
|
||||
// 正确
|
||||
if (address.isEmpty())
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < 10;i)
|
||||
qDebug("%i", i);
|
||||
for (int i = 0; i < 10;i)
|
||||
qDebug("%i", i);
|
||||
```
|
||||
|
||||
- 例外1:如果父语句跨多行,则使用大括号
|
||||
@ -213,35 +214,40 @@ it;
|
||||
|
||||
- case 和 switch 位于同一列
|
||||
- 每一个case必须有一个break(或renturn)语句,或者用注释说明无需break
|
||||
``` c++
|
||||
switch (myEnum) {
|
||||
case Value1:
|
||||
|
||||
```c++
|
||||
switch (myEnum) {
|
||||
case Value1:
|
||||
doSomething();
|
||||
break;
|
||||
case Value2:
|
||||
break;
|
||||
case Value2:
|
||||
doSomethingElse();
|
||||
// fall through
|
||||
default:
|
||||
// fall through
|
||||
default:
|
||||
defaultHandling();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
```
|
||||
|
||||
### 断行
|
||||
|
||||
- 保持每行短于100 个字符,需要时进行断行
|
||||
- 逗号放一行的结束,操作符放到一行的开头。如果你的编辑器太窄,一个放在行尾的操作符不容易被看到。
|
||||
// 正确
|
||||
if (longExpression
|
||||
+ otherLongExpression
|
||||
+ otherOtherLongExpression) {
|
||||
}
|
||||
|
||||
// Wrong
|
||||
if (longExpression +
|
||||
otherLongExpression +
|
||||
otherOtherLongExpression) {
|
||||
}
|
||||
```cpp
|
||||
// 正确
|
||||
if (longExpression
|
||||
+ otherLongExpression
|
||||
+ otherOtherLongExpression) {
|
||||
}
|
||||
|
||||
// Wrong
|
||||
if (longExpression +
|
||||
otherLongExpression +
|
||||
otherOtherLongExpression) {
|
||||
}
|
||||
```
|
||||
|
||||
### 继承与关键字 `virtual`
|
||||
|
||||
- 重新实现一个虚函数时,头文件中 不 放置 virtual 关键字。
|
||||
|
||||
Reference in New Issue
Block a user