自我指涉的结构定义? [英] self referential struct definition?
本文介绍了自我指涉的结构定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我还没有被编写C很长,所以我不知道应该怎么去这样做这类的事情递归...我想每个单元包含另一个细胞,但我得到一个沿着字段'孩子'的类型不完全的线路错误。这是怎么回事?
I haven't been writing C for very long, and so I'm not sure about how I should go about doing these sorts of recursive things... I would like each cell to contain another cell, but I get an error along the lines of "field 'child' has incomplete type". What's up?
typedef struct Cell {
int isParent;
Cell child;
} Cell;
PS(齐格也明确的typedef困惑:他已经通过typedef 细胞
到细胞
键,想知道为什么?)
PS (Ziggy is also clearly confused by typedef: he has typedefed Cell
to Cell
and wonders why?)
推荐答案
显然,一个细胞不能包含另一个细胞,因为它成为一个永无止境的递归。
Clearly a Cell cannot contain another cell as it becomes a never-ending recursion.
然而,一个单元格可以包含一个指向另一个单元。
However a Cell CAN contain a pointer to another cell.
typedef struct Cell {
bool isParent;
struct Cell* child;
} Cell;
这篇关于自我指涉的结构定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文