在我继续之前,这是给我一个错误的代码:
#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
我在顶部有一个 block 注释,因此行号已关闭,但是
第 17 行是第一行“struct btreenode{
”
第 28 行是最后一行“typedef struct btreenode *Node
”
有谁知道我为什么会收到这些错误?
最佳答案
头文件不应包含多次。所以在头文件中使用宏来避免多重包含。
#ifndef TEST_H__
#define TEST_H__
/*you header file can have declarations here*/
#endif /* TEST_H__*/
我假设,您的头文件中没有这种方法。
关于C、 "conflicting types for... "错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21718562/