在哪里放置包含语句、标题或来源? [英] Where to put include statements, header or source?
本文介绍了在哪里放置包含语句、标题或来源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该将包含在头文件中还是源文件中?如果头文件包含包含语句,那么如果我在源文件中包含该头文件,那么我的源文件是否会包含我的头文件中的所有包含文件?还是应该只将它们包含在我的源文件中?
Should I put the includes in the header file or the source file? If the header file contains the include statements, then if I include that header file in my source, then will my source file have all of the included files that were in my header? Or should I just include them in my source file only?
推荐答案
只有在 header 本身需要的时候才将 include 放在 header 中.
Only put includes in a header if the header itself needs them.
例子:
- 您的函数返回类型
size_t
.然后#include <stddef.h>
在header文件中. - 您的函数使用
strlen
.然后在source文件中#include <string.h>
.
- Your function returns type
size_t
. Then#include <stddef.h>
in the header file. - Your function uses
strlen
. Then#include <string.h>
in the source file.
这篇关于在哪里放置包含语句、标题或来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文