【发布时间】:2014-03-10 05:24:34
【问题描述】:
在我继续之前,这是给我一个错误的代码:
#define numScores 3 // the number of test scores which a student will have
struct btreenode{
int studentID; // the ID number of the student at the current node
float scores[3]; // the 3 test scores of the student
float average; // the average of the 3 test scores for the student
struct btreenode *left; // pointer to left side of the tree
struct btreenode *right; // pointer to right side of the tree
};
typedef struct btreenode *Node;
编译时出现以下错误:
btreenode.h:17: error: redefinition of 'struct btreenode'
btreenode.h:28: error: conflicting types for 'Node'
btreenode.h:28: note: previous declaration of 'Node' was here
我在顶部有一个块注释,所以行号是关闭的,但是
第 17 行是第一行“struct btreenode{”
第 28 行是最后一行“typedef struct btreenode *Node”
有人知道我为什么会收到这些错误吗?
【问题讨论】:
-
你的意思是
struct btreenode *Node;? -
对我来说没有错误。 See online demo of successful compilation.
-
也为我编译成功。
-
@jlzizmor 如果您在源文件
.c文件中也声明了相同的结构或在源文件中包含两次头文件,则可能会出现此错误。您可以显示源文件和头文件。 -
看起来您不止一次地包含了具有这些定义的文件。使用标题保护。
标签: c struct compiler-errors typedef redefinition