Reputation: 389
I'm doing a huffman encoding algorithm in C and got in a problem here.
I have two different .h files that will use this struct:
typedef struct no{
int qtd;
char c;
struct no* esq;
struct no* dir;
}no;
So, my arv_huffman.h has that typedef and typedef no** arvHuffman
My other .h, heap.h, includes "arv_huffman.h" and uses typedef no* heap
Both files have no other implementations. The message I get when I try to compile is:
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
lines have the following code
arv_huffman.h:11: "typedef struct no{"
arv_huffman.h:16: "}no;"
arv_huffman.h:18: "typedef no** arvoreHuff;"
What's going wrong and how do I fix it.
Upvotes: 0
Views: 353
Reputation: 13521
You forgot to put header guards in your .h
Since the guards aren't present, it is seeing the same definition twice, and thinks you are redefining the struct.
Upvotes: 5