【发布时间】:2014-11-16 09:38:23
【问题描述】:
我有两个 .h 文件和一个 .c 文件,如下所示
啊.h
typedef struct mode_info_t_ mode_info_t;
struct common {
int create;
mode_info_t *mode_info;
};
b.h
typedef struct mode_info_t_ {
int primary;
int secondary;
} mode_info_t;
main.c
#include "a.h"
#include "b.h"
-----
.c 编译时会抛出以下错误 -
b.h:17:错误:重新定义 typedef 'mode_info_t'
a.h:50: 错误:'mode_info_t' 的先前声明在这里
专家这里有什么问题?
【问题讨论】:
-
我不是 typedef 方面的专家,但您要对 mode_info_t 进行两次类型定义,一次是作为另一个变量,一次是作为结构......还有什么要说的?
-
这正是错误所说的......你重新定义了一个类型。不是
struct mode_info_t_,而是mode_info_t,你已经输入了它。 -
@BLUEPIXY 你是对的。还有一件事是为什么要为同一个结构多次执行
typedef。并且在结构中还有用户定义的数据类型? -
如何在 a.h 中为 mode_info_t 做前向声明?
-
在 b.h 中,尝试将
typedef struct mode_info_t_ {更改为struct mode_info_t_ {(并在结构定义后删除“mode_info_t”),这样您就可以定义struct mode_info_t_而无需重复mode_info_t的 typedef
标签: c struct compilation typedef header-files