C++ Header order(C++ 头文件顺序)
问题描述
header/cpp 文件中的 headers 应该以什么顺序声明?显然,后续标头所需的那些应该更早,并且特定于类的标头应该在 cpp 范围内而不是标头范围内,但是是否有固定的顺序约定/最佳实践?
What order should headers be declared in a header / cpp file? Obviously those that are required by subsequent headers should be earlier and class specific headers should be in cpp scope not header scope, but is there a set order convention / best practice?
推荐答案
在头文件中,您必须包含所有头文件才能使其可编译.并且不要忘记使用前向声明而不是某些标头.
In a header file you have to include ALL the headers to make it compilable. And don't forget to use forward declarations instead of some headers.
在源文件中:
- 对应的头文件
- 必要的项目标题
- 第三方库标头
- 标准库头文件
- 系统标头
按此顺序,您将不会错过任何忘记自己包含库的头文件.
In that order you will not miss any of your header files that forgot to include libraries by their own.
这篇关于C++ 头文件顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 头文件顺序


基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01