dictionary.h:
#ifndef __DICTIONARY_H
#define __DICTIONARY_H
typedef struct Dictionary Dictionary;
.
.
.
#endif
dictionary.c:
typedef struct Dictionary{
int* keys;
int* values;
int topIndex;
int keysSize;
int valuesSize;
}Dictionary;
我的老师告诉我不要在.h文件中实现typedef,所以我在.c文件中做到了,但是尝试编译时,出现关于重新定义它的错误。
我试图删除.h文件中的定义,但出现错误,因为返回typedef的函数现在返回未定义的类型。
我该如何解决?
C11之前的C不支持typedef
重新定义。
如果您包含了包含typedef struct Dictionary Dictionary;
的标头,则如果您想支持那些较早的C实现,则struct Dictionary
定义不应重新引入typedef
名称。也就是说,只需在C文件中执行struct Dictionary{ /*...*/ };
。