在 header 中使用来自不同文件的结构
using a struct from a different file in a header
我在文件 a.h 中定义了一个结构(暂且称之为测试),这个结构应该被许多文件使用。
在文件 b.h 中,我需要使用这个结构,但不是作为指针(struct test a[32]
而不是 struct test* a
)作为另一个结构的属性之一(我们称它为 test_container).
但我收到 error: array type has incomplete element type
。
我猜这是因为编译器不知道测试结构,所以它无法确定 space 需要多少 test_container。
所以我试图在 b.h 中添加 #include <a.h>
,但我收到 fatal error: a.h: No such file or directory
。这两个文件都在同一个目录中。
有什么问题?
使用 #include "a.h"
来包含您自己的 .h
。
顺便说一句,你应该post真实的代码而不是描述。
我在文件 a.h 中定义了一个结构(暂且称之为测试),这个结构应该被许多文件使用。
在文件 b.h 中,我需要使用这个结构,但不是作为指针(struct test a[32]
而不是 struct test* a
)作为另一个结构的属性之一(我们称它为 test_container).
但我收到 error: array type has incomplete element type
。
我猜这是因为编译器不知道测试结构,所以它无法确定 space 需要多少 test_container。
所以我试图在 b.h 中添加 #include <a.h>
,但我收到 fatal error: a.h: No such file or directory
。这两个文件都在同一个目录中。
有什么问题?
使用 #include "a.h"
来包含您自己的 .h
。
顺便说一句,你应该post真实的代码而不是描述。