两个头文件相互包含时出现的问题

//在头文件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; 就可以了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值