我正在用 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/