在另一个头文件中包含一个头文件 [英] Include a header in another header file
问题描述
我在 .h 文件中定义了一个 struct item
.现在我在另一个 .h 中定义另一个 struct tPCB
这是同一个项目的一部分,我需要 tPCB
有一个 item
.我认为仅仅制作同一个 TurboC 项目的一部分就可以让我在另一个头文件中使用 item,但是编译器会抛出undefined type:ite
".
I've defined a struct item
in a .h file. Now I'm defining another struct tPCB
in another .h which is part of the same project, and I need the tPCB
to have an item
. I thought that just making part of the same TurboC project would allow me to use item in the other header file, but the compiler throws me "undefined type: ite
".
我想我必须以某种方式在第二个标题中包含第一个标题,但是我看到了相同的类似代码,但不这样做.
I guess I somehow have to include the first header on the second one, However I have seen the same a similar code which works without doing so.
除了添加 #include
行之外,还有其他方法可以让它工作吗?
Is there any other way than just adding an #include
line to make it work?
推荐答案
如果你的 .c #include
s 这两个 .h 文件的顺序正确,它会起作用.这可能就是你记得的案例中发生的事情.最安全的做法是 #include
每个定义依赖项的文件,并依靠每个 .h 中的包含保护来防止被多次定义.
If your .c #include
s the two .h files in the proper order, it will work. That's probably what happened in the case you remember. The safest course is to #include
every file that defines your dependencies, and rely on the include guards in each .h to keep things from being multiply defined.
这篇关于在另一个头文件中包含一个头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!