c - Visual C 2012 : I am getting weird errors. 提供代码段和错误

标签 c

我正在用 C 语言编写游戏。但我不断收到一些错误。其中一个突出的就是这个。 “非法标识符:X”,其中 X 是结构内变量的类型。实例 Illegal Identifier: MapItem 是由以下代码引起的

typedef struct MapItem{
int item;
int count;
};

typedef struct MapTile{
MapItem item;
int x;
int y;
int tile;
Direction dir;
int drop;
};

错误附加到 MapTile 结构内的第一行。我想知道为什么会出现此错误以及如何修复它。

代码段是按照准确的顺序从map.h 中获取的。 Direction 是之前在同一 header 中声明的枚举。

谢谢大家的回答。然而,我确实在 4 小时前收到了我需要的答案。

最佳答案

您的 typedef 不正确。语法为:

typedef type typealias ;

所以:

typedef struct 
{
    int item;
    int count;
} MapItem;

typedef struct
{
    MapItem item;
    int x;
    int y;
    int tile;
    Direction dir;
    int drop;
} MapTile;

请注意,此处别名的类型匿名结构,仅自引用结构需要结构标签。

关于c - Visual C 2012 : I am getting weird errors. 提供代码段和错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44708193/

相关文章:

c - 仅打印字符串中的字母

使用 char 和 strcmp 比较 c 中的两个数字

c - 奇怪的错误,将 char 与字符串进行比较 (p == "cancel")

c++ - 使用 PoDoFo 库从 PDF 运算符中的数组 TJ 中提取文本

缓存未命中和缓存命中

c - 如何设置和管理持久多线程?

c++ - 当 define 对运算符有值(value)时,#define 如何在编程中工作?

c - while 中的 if 语句依赖于 while 依赖的同一个变量

C 编程 - 返回无法正常工作

c - 如何使用 GTK3 在 C 中将 GtkWidget 标签对齐到其 GtkWidget 布局的中心?