cpp报错:C-struct error-Field has incomplete type
Posted Harris-H
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cpp报错:C-struct error-Field has incomplete type相关的知识,希望对你有一定的参考价值。
cpp报错:C-struct error-Field has incomplete type
程序定义如下代码:
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.指针不需要一个完整的类定义来声明
以上是关于cpp报错:C-struct error-Field has incomplete type的主要内容,如果未能解决你的问题,请参考以下文章
将 c-struct 放入 NSArray 的最佳方法是啥?
在 Swift 中使用 const char * 初始化 C-struct