本文介绍了C ++标题顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在header / cpp文件中应该声明什么顺序头文件?显然,后续头文件所需的那些应该更早,类特定的头文件应该在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.
在源文件中:
- 相应的头文件
- 必要的项目标题
- 第三方库标题
- libraries headers
- 系统标题
- corresponded header file
- necessary project headers
- 3rd party libraries headers
- standard libraries headers
- system headers
按此顺序,您不会错过任何头文件忘记包含自己的图书馆了。
In that order you will not miss any of your header files that forgot to include libraries by their own.
这篇关于C ++标题顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!