使用另一个头文件 - c 的头文件
c代码,头文件问题。
我有一个头文件(list.h)定义两个链表结构,另一个queue.h包含队列的定义。
list.h 中定义了一个包含列表和队列的结构体,因此它依赖于queue.h 文件。
包含所有其他结构的结构在 list.h 文件中定义,处理它的函数在 list.c 文件中定义。因此,这两个文件都需要包含queue.h。
但是,如果我将其包含在 list.h 和 list.c 文件中,则会出现以下错误。
..\/queue.h:13:16: error: redefinition of 'struct qqq'
..\/queue.h:13:16: note: originally defined here
如果不是其中之一,则存在导致标头丢失的其他错误: 它没有定义包含队列的结构。
有什么办法可以做到这一点...?
Possible Duplicate:
How to declare a structure in a header that is to be used by multiple files in c?
c code, header file issue.
I have a header (list.h) file defining two linked list structures, and another queue.h which includes the definition of a queue.
There is a struct that includes the lists and queue together, defined in list.h, which therefore depends on the queue.h file.
A struct containing all the others is defined in the list.h file and the functions that deal with it are defined in the list.c file. Consequently both files need to include queue.h.
However if i include it in both the list.h and list.c files i get the following error.
..\/queue.h:13:16: error: redefinition of 'struct qqq'
..\/queue.h:13:16: note: originally defined here
if not in one or the other then other errors to the effect that the header is missing:
it doesn't define the structure containing the queue.
Is there any way to do this...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该使用
#ifndef
预处理器语句来防止头文件的内容要包含两次:queue.h:
只需为所有头文件添加此内容(每次使用不同的常量),它就会起作用。
You should use the
#ifndef
preprocessor statement to prevent the content of your headers to be included twice :queue.h:
Simply to this for all your header files (with different constants each time), and it will work.
包含守卫 在这种情况下会很有帮助。
Include Guards will be helpful in this case.
使用它来定义列表和队列头文件
use this to define the both list and queue header files