自引用结构定义?我写C的时间不长,所以我不确定该如何做这些递归的事情.我希望每个单元格包含另一个单元格,但是我会得到一个错误,类似于“字段‘子”有不完整的类型“。出什么事啦?typedef struct Cell {
int isParent;
Cell child;} Cell;
3 回答
忽然笑
TA贡献1806条经验 获得超5个赞
typedef struct Cell { bool isParent; struct Cell* child;} Cell;
天涯尽头无女友
TA贡献1831条经验 获得超9个赞
#include <stdio.h>#include <stdlib.h>typedef struct Cell { int cellSeq; struct Cell* next; /* 'tCell *next' will not work here */} tCell;int main(void) { int i; tCell *curr; tCell *first; tCell *last; /* Construct linked list, 100 down to 80. */ first = malloc (sizeof (tCell)); last = first; first->cellSeq = 100; first->next = NULL; for (i = 0; i < 20; i++) { curr = malloc (sizeof (tCell)); curr->cellSeq = last->cellSeq - 1; curr->next = NULL; last->next = curr; last = curr; } /* Walk the list, printing sequence numbers. */ curr = first; while (curr != NULL) { printf ("Sequence = %d\n", curr->cellSeq); curr = curr->next; } return 0;}
struct Cell
typedef
tCell
慕容森
TA贡献1853条经验 获得超18个赞
struct Cell { bool isParent; struct Cell* child;};struct Cell;typedef struct Cell Cell;
- 3 回答
- 0 关注
- 391 浏览
添加回答
举报
0/150
提交
取消