2011-11-10 56 views
0

我正在C中做一個huffman編碼算法,並在這裏遇到了問題。在多個.h文件中使用typedef結構

我將使用此結構兩個不同的.h文件:

typedef struct no{ 
    int qtd; 
    char c; 
    struct no* esq; 
    struct no* dir; 
}no; 

所以,我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 

線有下面的代碼

arv_huffman.h:11: "typedef struct no{" 
arv_huffman.h:16: "}no;" 
arv_huffman.h:18: "typedef no** arvoreHuff;" 

出現了什麼問題?如何解決它。

回答

5

你忘了header guards在您的.h

由於警衛不存在,它看到了同樣的定義兩次,並認爲你正在重新定義結構。

+0

像魔術一樣工作,謝謝! – Adriano