c - 在 C 中创建递归数据结构的方法
问题描述
解决方案
Person
is not defined yet, since the typedef only takes effect after the semicolon concluding it. To refer to the struct from within itself, use struct Person
. The following code compiles with no errors on GCC 10.2.0.
typedef struct Person {
char* name;
struct Person* mother;
struct Person* father;
} Person;
int main() {
Person Kathy = { "Kathy", NULL, NULL };
Person Bill = { "Bill", NULL, NULL };
Person Bob = { "Bob", &Kathy, &Bill };
return 0;
}
推荐阅读
- vue.js - 如何单独设置芯片颜色
- python - 在 Python 中删除列表中重复项的最快方法?
- c# - 使用 NEST 为 ElasticSearch 配置标准停用词
- python - 我想知道如何由创建它的用户实际更新对象
- javascript - 带有jquery的codeigniter调用函数没有重新加载
- reactjs - 反应formik在外面读取输入值
实时onchange - javascript - 当我在 javascript 上使用标签时,为什么不能通过 css 设置标签样式?
- python - 将不同的条目打印到一行中(列表框,tkinter)
- javascript - 括号在 chrome devtools 内存选项卡中的含义
- scala - Scala 表格打印