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++ 头文件顺序
基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01