在C中做这样的事情是不可能的吗?
struct room{
//Name of the room
char* name;
//Type fo the room
char* type;
//Array of outbound connections, max of six
struct room connections[6];
//A counter variable for how many connections the room actually has been assigned
int numOfConnections;
};
我正在创建一个相互连接的房间的地图,我认为每个房间跟踪它所连接的房间的最简单方法是创建一个房间结构数组,然后将这些房间放入它们的结构中。
我得到一个错误,说房间数组有一个不完整的元素类型。错误出现在"struct room connections6;“行上。
发布于 2018-09-03 06:41:07
为了在自身内部存储struct
,它必须是指针类型。否则,如注释中所述,此struct
将占用无限空间。下面的更改使其成为指向6个struct room
的指针。
struct room{
//Name of the room
char* name;
//Type fo the room
char* type;
//Array of outbound connections, max of six
struct room* connections[6];
//A counter variable for how many connections the room actually has been assigned
int numOfConnections;
};
https://stackoverflow.com/questions/52141388
复制相似问题