【发布时间】:2012-03-05 03:34:27
【问题描述】:
我在尝试 malloc 这个结构时遇到了一个小问题。 这是结构的代码:
typedef struct stats {
int strength;
int wisdom;
int agility;
} stats;
typedef struct inventory {
int n_items;
char **wepons;
char **armor;
char **potions;
char **special;
} inventory;
typedef struct rooms {
int n_monsters;
int visited;
struct rooms *nentry;
struct rooms *sentry;
struct rooms *wentry;
struct rooms *eentry;
struct monster *monsters;
} rooms;
typedef struct monster {
int difficulty;
char *name;
char *type;
int hp;
} monster;
typedef struct dungeon {
char *name;
int n_rooms;
rooms *rm;
} dungeon;
typedef struct player {
int maxhealth;
int curhealth;
int mana;
char *class;
char *condition;
stats stats;
rooms c_room;
} player;
typedef struct game_structure {
player p1;
dungeon d;
} game_structure;
这是我遇到问题的代码:
dungeon d1 = (dungeon) malloc(sizeof(dungeon));
它给了我错误“错误:请求转换为非标量类型” 有人可以帮我理解这是为什么吗?
【问题讨论】: