C, "conflicting types for ..."

Before continuing, here is the code that gives me an error:

#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;

When compiling, I get the following error:

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

I have a block comment on top, so line numbers are disabled, but

line 17 is the first line " struct btreenode{"

line 28 is the last line " typedef struct btreenode *Node"

Does anyone know why I am getting these errors?

+3
source share
2 answers

The header file should not be included more than once. Therefore, use a macro in the header file to avoid multiple inclusion.

#ifndef TEST_H__
#define TEST_H__

/*you header file can have declarations here*/

#endif /* TEST_H__*/

I assume that this type of approach is not in your header file.

+6
source

, btreenode.h ( ) ... " " " " ( , , ).

( btreenode.h), , . :

#ifndef BTREENODE_H
#define BTREENODE_H

:

#endif // BTREENODE_H

, , , , BTREENODE_H #define d .

+1

All Articles