南京捷帝科技有限公司
laoxiaketang.com
老夏课堂 C++编程规范
目录
1.
头文件规则...........................................................................................................................................2
1.1. #define 防止多重包含............................................................................................................. 2
1.2. 减少头文件依赖.......................................................................................................................2
1.3. 头文件中不导入命名空间.......................................................................................................3
2.
类规则...................................................................................................................................................4
2.1. 构造函数(Constructor)的职责.......................................................................................... 4
2.2. 结构体和类(Structs vs. Classes).....................................................................................4
2.3. 继承(Inheritance)...............................................................................................................4
2.4. 多重继承(Multiple Inheritance)........................................................................................ 4
2.5. 接口(Interface)................................................................................................................... 4
2.6. 声明次序(Declaration Order)........................................................................................... 5
3.
格式规则...............................................................................................................................................5
3.1. 空格还是制表位(Spaces vs. Tabs)................................................................................. 5
3.2. 括号格式...................................................................................................................................5
4.
命名约定...............................................................................................................................................5
4.1. 通用命名规则(General Naming Rules).......................................................................... 5
4.2. 文件命名(File Names)...................................................................................................... 6
4.3. Class 类型命名(Type Names)..........................................................................................6
4.4. 变量命名(Variable Names).............................................................................................. 6
4.5. 函数命名(Function Names)............................................................................................. 6
普通函数:...............................................................................................................................6
成员存取函数:....................................................................................................................... 6
4.6. 宏、枚举命名...........................................................................................................................7
使用全部大写+下划线.............................................................................................................7
5. Doxygen
注释规则.................................................................................................................................7
5.1. 文件注释...................................................................................................................................7
5.2. 类定义注释...............................................................................................................................7
5.3. 常量/变量的注释..................................................................................................................... 8
5.4. 函数注释...................................................................................................................................8