可能重复:
How to declare a structure in a header that is to be used by multiple files in 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
如果不是在一个或另一个,然后其他错误,大意是报头丢失: 它没有定义包含队列的结构。
有没有办法做到这一点......?
http://en.wikipedia.org/wiki/Include_guard是你需要的;) – Chris 2011-03-31 11:31:03
我喜欢这个想法(谢谢所有),它非常有意义,但是当我实现它时,我得到了'D:\ workspace \ swap \ Debug \../ pre boolean remote/swap.c:22:多重定义'main' swap.o:D:\ workspace \ swap \ Debug /../ swap.c:22:对于许多功能(prob all)。试图找到任何明显的原因,但没有运气到目前为止 – commentator8 2011-03-31 11:47:33