问问题
575 次
2 回答
3
你需要改变
typedef struct {
至
typedef struct Cell {
定义了一个无typedef struct { /* ... */ } Cell;
标签结构。实际上,结构本身没有可以直接引用的名称。该名称Cell
只是typedef
引用此未命名结构的 a 的名称。
当您使用struct Cell
to declarenext
时,它表示“名为 的结构Cell
”。但是,没有一个名为 的结构Cell
,因为您定义的结构没有名称。
通过命名结构(给它一个标签),您可以使用struct Cell
符号来引用它。
于 2012-07-21T20:34:18.623 回答
2
您需要为您的 提供标签struct
,而不仅仅是 typedef:
typedef struct Cell {
element_type e;
struct Cell *next;
} Cell,*List;
如果没有标签,struct Cell *
则未定义,导致错误。
理解这个 typedef 的结构非常有帮助:它是两个声明的组合:
struct Cell {
element_type e;
struct Cell *next;
};
和
typedef struct Cell Cell;
没有标签,你就是typedef
一个无标签的struct
。
于 2012-07-21T20:34:26.247 回答