在多个.h文件中使用typedef结构

Adr*_*ano 0 c struct typedef header

我在C中做了一个霍夫曼编码算法,并在这里遇到了问题.

我有两个不同的.h文件将使用此结构:

typedef struct no{
  int qtd;
  char c;
  struct no* esq;
  struct no* dir;
}no;
Run Code Online (Sandbox Code Playgroud)

所以,我的arv_huffman.h有那个typedef和 typedef no** arvHuffman

我的另一个.h,heap.h,包含"arv_huffman.h"并使用 typedef no* heap

这两个文件都没有其他实现.我尝试编译时得到的消息是:

arv_huffman.h:11: error: redefinition of ‘struct no’
arv_huffman.h:16: error: conflicting types for ‘no’
arv_huffman.h:16: note: previous declaration of ‘no’ was here
arv_huffman.h:18: error: conflicting types for ‘arvoreHuff’
arv_huffman.h:18: note: previous declaration of ‘arvoreHuff’ was here
Run Code Online (Sandbox Code Playgroud)

行具有以下代码

arv_huffman.h:11: "typedef struct no{"
arv_huffman.h:16: "}no;"
arv_huffman.h:18: "typedef no** arvoreHuff;"
Run Code Online (Sandbox Code Playgroud)

出了什么问题,我该如何解决它.

Tod*_*ner 5

你忘了把头放在你的.h

由于守卫不存在,它两次看到相同的定义,并认为你正在重新定义结构.