From 39fc9c4c7ef68ea55aa041bbd844863db306a323 Mon Sep 17 00:00:00 2001 From: abdulla Date: Mon, 15 Jul 2024 15:24:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AC=A1=E6=8F=90=E4=BA=A4=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 代码规范/README.md | 23 +++++++++++ 代码规范/cppStyleGuide/StyleGuide.md | 61 ++++++++++++++++++++++++++++ 代码规范/gitStore/git.md | 1 + 3 files changed, 85 insertions(+) create mode 100644 代码规范/README.md create mode 100644 代码规范/cppStyleGuide/StyleGuide.md create mode 100644 代码规范/gitStore/git.md diff --git a/代码规范/README.md b/代码规范/README.md new file mode 100644 index 0000000..2de15f1 --- /dev/null +++ b/代码规范/README.md @@ -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 + +* 快速搭建基础项目(持续更新) +* 编译器配置(持续更新) diff --git a/代码规范/cppStyleGuide/StyleGuide.md b/代码规范/cppStyleGuide/StyleGuide.md new file mode 100644 index 0000000..957e19c --- /dev/null +++ b/代码规范/cppStyleGuide/StyleGuide.md @@ -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 +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] \ No newline at end of file diff --git a/代码规范/gitStore/git.md b/代码规范/gitStore/git.md new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/代码规范/gitStore/git.md @@ -0,0 +1 @@ + \ No newline at end of file