jlz*_*mor 5 c struct typedef compiler-errors redefinition
在继续之前,这是给我一个错误的代码:
#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;
Run Code Online (Sandbox Code Playgroud)
编译时我收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
我在顶部有一个块注释,因此行号已关闭,但是
第17行是第一行" struct btreenode{"
第28行是最后一行" typedef struct btreenode *Node"
有谁知道我为什么会收到这些错误?
头文件不应包含多次.因此,在头文件中使用宏来避免多次包含.
#ifndef TEST_H__
#define TEST_H__
/*you header file can have declarations here*/
#endif /* TEST_H__*/
Run Code Online (Sandbox Code Playgroud)
我认为,这种方法不在你的头文件中.
| 归档时间: |
|
| 查看次数: |
14934 次 |
| 最近记录: |