【发布时间】:2011-01-24 14:03:27
【问题描述】:
好的,我非常了解如何在 C 程序中使用头文件,但是我一直遇到这个问题,我似乎无法解决。情况如下:
Device.c 包含#include "Device.h"
Device.h 包含一个结构的定义和以下...
#ifndef DEVICE_H
#define DEVICE_H
#include "SubDevice.h"
typedef struct {
subDevice * subDevice1;
subDevice * subDevice2;
} device;
#endif
SubDevice.c 包含#include SubDevice.h
SubDevice.h 包含 subDevice 结构体的定义以及以下...
#ifndef SUBDEVICE_H
#define SUBDEVICE_H
#include "Device.h"
typedef struct{
int MyInt;
double MyDouble;
}subDevice;
#endif
问题是我在结构定义中的 Device.h 中遇到编译器错误。在subDevice * subDevice1; 行上写着syntax error before subDevice。
问题是我在每个文件中都包含另一个文件的头文件吗?我认为#ifndef - #define 语句可以防止导致问题...
【问题讨论】:
-
我不认为
#include DEVICE_H是正确的。 -
SubDevice.h 中的结构真的有名字吗?
-
哎呀,我在帖子中错过了这一点。我编辑了它。
-
这仍然是错误的 - 将:
#include DEVICE_H更改为#include "Device.h"或您在实际标题中需要的任何内容。 -
@Jordan S:你确定分号也出现在你的实际来源中吗?