内部结构的C / C ++的结构 [英] Structures inside Structures C/C++

查看:159
本文介绍了内部结构的C / C ++的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚切换从Java编程的C / C ++编程所以请原谅我,如果这是一个愚蠢的问题:

I just recently switched over from Java programming to C/C++ programming so forgive me if this is a silly question:

我有由一结构,其包括从一不同位置的另一头文件2结构的头文件。它看起来是这样的:

I have a header file which is composed of a structure which includes 2 structures from another header file in a different location. It looks something like this:

struct A {
   struct B variable1;
   struct C *variable2;
   ... more variable declarations here.
};

它包含结构B和结构C中的声明的头文件不包含在这个特定的头文件,但即使我使用了它们没有区别 - 在编译时这两种情况下,我得到

The header files which contains the declarations for struct B and struct C are not included in this specific header file, but even if I do include them it makes no difference - in both scenarios at compilation time I get

error: field 'variable1' has incomplete type

我只是想知道,如果有人知道这可能是从什么?
谢谢!

I am just wondering if anyone knows what this could be from? Thank you!

推荐答案

如果您不包括结构乙的定义,你应该得到提到的错误,因为该结构的尺寸是则不明。结构ç类型的到你只有一个指针可能仅仅是pre-声明:

If you don't include the definition of struct B you should get the mentioned error, since the size of the structure is then unknown. The type of struct C to which you only have a pointer could just be pre-declared:

struct C;

如果你包括结构乙的定义文件,你不应该得到的错误,所以,如果你仍然这样做,在你的$其他错误点C $角

If you do include the file with the definition of struct B, you should not get the error, so if you still do that points at some other error in your code.

这篇关于内部结构的C / C ++的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆