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++ 头文件顺序


- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- C++ 协变模板 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- STL 中有 dereference_iterator 吗? 2022-01-01
- 近似搜索的工作原理 2021-01-01