C++ 头文件顺序 [英] C++ Header order

查看:35
本文介绍了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++ 头文件顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆