VS2015--win32工程配置的一些想法之Google Code Style中头文件的顺序
来源:互联网 发布:黑白格子裙图片淘宝 编辑:程序博客网 时间:2024/06/05 14:07
工程大了,有很多的头文件,也要引用很多的库文件。
从我们学习C++写hello world的那一刻起,就知道要包含一些系统文件。
那么顺序如何呢?
在review的时候,感觉自己写的东西就是一坨屎。
看看Google code style中是如何描述include文件顺序的:
Names and Order of Includes
Use standard order for readability and to avoid hidden dependencies: C library, C++ library, other libraries’ .h, your project’s .h.
All of a project’s header files should be listed as descendants of the project’s source directory without use of UNIX directory shortcuts . (the current directory) or .. (the parent directory). For example, google-awesome-project/src/base/logging.h should be included as
#include "base/logging.h"
In dir/foo.cc or dir/foo_test.cc, whose main purpose is to implement or test the stuff in dir2/foo2.h, order your includes as follows:
dir2/foo2.h (preferred location — see details below).
C system files.
C++ system files.
Other libraries’ .h files.
Your project’s .h files.
The preferred ordering reduces hidden dependencies. We want every header file to be compilable on its own. The easiest way to achieve this is to make sure that every one of them is the first .h file #included in some .cc.
dir/foo.cc and dir2/foo2.h are often in the same directory (e.g. base/basictypes_test.cc and base/basictypes.h), but can be in different directories too.
Within each section it is nice to order the includes alphabetically.
For example, the includes in google-awesome-project/src/foo/internal/fooserver.cc might look like this:
#include "foo/public/fooserver.h" // Preferred location.#include <sys/types.h>#include <unistd.h>#include <hash_map>#include <vector>#include "base/basictypes.h"#include "base/commandlineflags.h"#include "foo/public/bar.h"
这用通俗的讲,你写了一个a.h和a.cc,而在.cc文件中需要用到一些通用的东西位于base文件夹下的base.h中。那么在a.cc文件中,你就应该这样的顺序包含:
#include a.h#include <sys/types.h> #include <algorithm>#include "base/base.h"
- VS2015--win32工程配置的一些想法之Google Code Style中头文件的顺序
- VS2015--win32工程配置的一些想法之cmake
- VS2015--win32工程配置的一些想法之cmake
- VS2015--win32工程配置的一些想法之在 Visual Studio 2015 中进行调试的同时分析性能
- VS2015--win32工程配置的一些想法之预处理器不起作用
- VS2015--win32工程配置的一些想法之VS2015编译的程序在其他机器上缺少msvcp120.dll
- VS2015--win32工程配置的一些想法之warning LNK4042: 对象被多次指定;已忽略多余的指定
- VS2015--win32工程配置的一些想法之算法min/max与windows中的 min/max宏冲突
- VS2015--win32工程配置的一些想法之GdiplusTypes.h(470) : error C3861: 'min': identifier not found
- VS2015--win32工程配置的一些想法之警告:“BOOL”: 将值强制为布尔值“true”或“false”(性能警告)
- Stolen Code的一些想法
- VS2015的头文件加载
- Google C++ Style----头文件
- google C++编程风格指南之头文件的包含顺序
- C++ - 工程中头文件的定义
- 【VS开发】利用VS2015的工程文件来复制另外一个工程的配置的使用说明
- vs2015学习opencv330_64位的工程配置
- style文件的一些属性
- 【MATLAB】关系运算与逻辑运算
- 一些关于linux的总结
- LeetCode 171. Excel Sheet Column Number & 168. Excel Sheet Column Title
- 大型网站系统架构演化之路
- 读《A Guide To iOS Animation》-AnimatedCircleDemo
- VS2015--win32工程配置的一些想法之Google Code Style中头文件的顺序
- Must Know Tips/Tricks in Deep Neural Networks (by Xiu-Shen Wei)
- 使用crontab定时执行脚本时别忘了输出重定向>
- ubuntu下安装程序的三种方法
- 手工创建maven 项目
- Android Wear 报错:cannot connect to localhost:4444: 由于目标计算机积极拒绝,无法连接。 (10061)
- 使用Android Studio开发遇到的问题
- ListView用SimpleAdapter显示图片和文本
- noj 1059 搬寝室