程序定义如下代码:
struct Node
{
Node son;
};
The error means that you try and add a member to the struct
of a type that isn’t fully defined yet, so the compiler cannot know its size in order to determine the objects layout.
In you particular case, you try and have struct Cat
hold a complete object of itself as a member (the mother
field). That sort of infinite recursion in type definition is of course impossible.
Nevertheless, structures can contain pointers to other instances of themselves.
这是stackoverflow上的一段解释,就是说这样用会造成无限递归
The recursion is in the type containing itself completely as a member.而这个递归就是在一个type中完全以它为类型作为一个成员。
但是可以用指针来代替
struct Node{
Node * son;
};
Why struct Cat *children
member does not make the type recursive? 指针类型为什么不会造成循环
because it’s a pointer. You don’t need the complete type definition to declare a pointer to it.指针不需要一个完整的类定义来声明