【问题标题】:using a struct from a different file in a header在标头中使用来自不同文件的结构
【发布时间】:2020-04-28 16:02:56
【问题描述】:

我在文件 a.h 中定义了一个结构体(我们称之为 test),这个结构体应该被许多文件使用。 在文件 b.h 中,我需要使用这个结构,但不能作为指针(struct test a[32] 而不是struct test* a)作为另一个结构的属性之一(我们称之为 test_container)。 但我收到了error: array type has incomplete element type。 我猜它的发生是因为编译器不知道测试结构,所以它不能阻止 test_container 需要多少空间。 所以我试图在 b.h 中添加#include <a.h>,但后来我收到了fatal error: a.h: No such file or directory。这两个文件都在同一个目录中。 有什么问题?

【问题讨论】:

  • 发布代码而不是代码描述。它更容易阅读,也更准确。也就是说,您可能应该#include "a.h"

标签: c struct include


【解决方案1】:

使用#include "a.h" 包含您自己的.h

顺便说一下,你应该发布真实的代码而不是描述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-12
    • 1970-01-01
    • 2015-02-16
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多