//在头文件test.h 中
#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
#include "SeqList.h" //包含SeqLit.h
struct QueueNode
{
struct Node data; //引用到SeqLit.h 中的struct Node
struct QueueNode *next;
};
#endif // TEST_H_INCLUDED
//在头文件SeqList.h 中
#ifndef SEQLIST_H_INCLUDED
#define SEQLIST_H_INCLUDED
#include "test.h" //包含 test.h
struct Node
{
struct Node *leftChild;
struct Node *rightChild;
int data;
};
typedef struct Node Tree;
typedef Tree *PTree;
void LevelOrder(struct Queue *queue,PTree p); //要引用到test.h 中的struct Queue
#endif // SEQLIST_H_INCLUDED
当两个头文件都相互包含时,在包含的顺序上就了现了问题
在以上的两个头文件中SeqList.h 先包含Test.h 呢?还是Test.h先包含SeqList.h呢?编译器在这时就不能决定,所以就出现了错误。
Win7/ gcc 中提示
error: field 'data' has incomplete type
要解决这个问题很简单,把SeqList.h中的#include "test.h" 替换成 struct Queue; 就可以了