Compare commits
1 Commits
c42c006b9a
...
abdulla
| Author | SHA1 | Date | |
|---|---|---|---|
| 39fc9c4c7e |
23
代码规范/README.md
Normal file
23
代码规范/README.md
Normal file
@ -0,0 +1,23 @@
|
||||
# [代码规范](./cppStyleGuide/StyleGuide.md)
|
||||
|
||||
引用模板
|
||||
|
||||
* [google cpp guide](https://google.github.io/styleguide/cppguide.html)
|
||||
* [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines)
|
||||
* Qt
|
||||
* osg
|
||||
* 源码文件编码(utf-8)
|
||||
|
||||
# [git仓库管理](./gitStore/git.md)
|
||||
* 仓库创建流程
|
||||
* git钩子
|
||||
|
||||
# 代码审查
|
||||
|
||||
* 代码规范检查
|
||||
* C/C++ 静态代码检查工具cppCheck
|
||||
|
||||
# CMake
|
||||
|
||||
* 快速搭建基础项目(持续更新)
|
||||
* 编译器配置(持续更新)
|
||||
61
代码规范/cppStyleGuide/StyleGuide.md
Normal file
61
代码规范/cppStyleGuide/StyleGuide.md
Normal file
@ -0,0 +1,61 @@
|
||||
# c++ 代码风格规范
|
||||
|
||||
## 源代码文件命名
|
||||
|
||||
##### 1. 前要
|
||||
|
||||
**通常情况下每个.cpp文件应该有一个配套的.h文件。当然也有例外的情况(例如:c++模板类的实现)。正确使用头文件会大大改善代码的可读性和执行文件的大小和性能.**
|
||||
|
||||
> 头文件应能独立编译,就是头文件的使用者和构建工具在导入文件时无需任何特殊的前提条件就能完成代码编译。具体来说,头文件要有头文件防护符,并导入它所需的所有其它头文件。
|
||||
> 当编写c++模板时应保证模板的实现声明和实现都在同一个文件里。一般,写模板时源码文件以.hpp命名。
|
||||
> 避免编写依赖某个构建工具的代码。(例如:项目的构建依赖于VSCode的一个插件,使用其他的构建工具,项目无法构建且生成)
|
||||
> 避免前向声明
|
||||
|
||||
##### 2. 文件命名
|
||||
|
||||
* **新建c++类[.h 或 .hpp]**
|
||||
|
||||
> 新建类文件时,尽量保证文件名与导出(外部调用)的类名保持一致(一个头文件中可能包含好几个类)。
|
||||
> Help.h
|
||||
|
||||
```cpp
|
||||
class Help{}
|
||||
```
|
||||
|
||||
Help.hpp
|
||||
|
||||
```cpp
|
||||
template<typename T>
|
||||
class Help{}
|
||||
```
|
||||
|
||||
##### 3. 防护符
|
||||
|
||||
* **要保证头文件带有防护重复引用预处理头**
|
||||
|
||||
```cpp
|
||||
#pragma once
|
||||
```
|
||||
|
||||
或
|
||||
|
||||
```cpp
|
||||
#ifndef HELP_H
|
||||
#define HELP_H
|
||||
|
||||
#endif
|
||||
```
|
||||
|
||||
## 命名规范
|
||||
|
||||
##### 1. 命名空间[namespace]
|
||||
##### 2. 类[class]
|
||||
##### 3. 结构体[struct]
|
||||
##### 4. 模板[template]
|
||||
##### 5. 私有函数或变量[private]
|
||||
##### 6. 共有函数或变量[public]
|
||||
##### 7. 受保护函数或变量[protected]
|
||||
##### 8. 预处理[#define]
|
||||
##### 9. 内联函数[inline]
|
||||
##### 10. 常量[const]
|
||||
##### 11. 静态变量或函数[static]
|
||||
1
代码规范/gitStore/git.md
Normal file
1
代码规范/gitStore/git.md
Normal file
@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user