我没有写C很长时间,所以我不确定我应该怎么做这些递归的东西...我希望每个单元格包含另一个单元格,但我得到一个错误沿着"田地'孩子'的行具有不完整的类型".这是怎么回事?
typedef struct Cell {
int isParent;
Cell child;
} Cell;
Run Code Online (Sandbox Code Playgroud) 在下面的表示中,
struct Cat{
char *name;
struct Cat mother;
struct Cat *children;
};
Run Code Online (Sandbox Code Playgroud)
编译器为第二个字段提供以下错误,但不是第三个字段,
error: field ‘mother’ has incomplete type
struct Cat mother;
^
Run Code Online (Sandbox Code Playgroud)
如何理解这个错误?
这可能很简单,但是如何在C中的struct x中得到一个struct x?例如:
typedef struct _Node {
Node node;
} Node;
Run Code Online (Sandbox Code Playgroud)
我做了一些研究并尝试使用指针,如下所示:
typedef struct _Node {
struct Node *node;
} Node;
Run Code Online (Sandbox Code Playgroud)
虽然这会将变量节点作为指针(我不想要),但我只想让它成为Node结构的一个实例.谢谢你的帮助.:)
编辑:
基本上我要做的是:
Node current = createNode(...);
while (true) {
Node node = createNode(..., ¤t);
addToList(node);
current = somethingElse();
}
Run Code Online (Sandbox Code Playgroud)
你可以想象,我想要一个常规节点进入createNode()函数:
Node createNode(..., Node node) {}
Run Code Online (Sandbox Code Playgroud)