gpt4 book ai didi

c - 结构体指针中的 "dereferencing pointer to incomplete type”

转载 作者:行者123 更新时间:2023-11-30 15:06:30 28 4
gpt4 key购买 nike

所以我在标题中定义了以下结构 path.h :

typedef struct path Path;

struct Path {

Path* branching_paths;
uint32_t nb_paths;
};

在同一个标​​头中,我声明并定义了以下内联函数:

  inline void init_path(Path* path);

inline void init_path(Path* path){

path->branching_paths = NULL;
path->nb_paths = 0;
}

我不知道我收到此错误的原因是什么。我已经搜索过网络,但据我所知,我已经在 header 中正确定义了结构,还是我遗漏了某些内容?

./../Path.h:54:9: error: dereferencing pointer to incomplete type 'Path {aka struct path}'
path->branching_paths = NULL;

最佳答案

您的 typedef 中有一个拼写错误。

您为struct path定义一个typedef,然后定义struct Path。由于 C 区分大小写,因此它们被视为两种不同的类型。

按照您现在的方式,您声明了struct path(使用Path作为别名),但尚未定义它。因此,当您尝试取消引用 Path * 时,编译器不知道该结构是什么样子,因为您没有告诉它。

你想要的是:

typedef struct Path Path;

关于c - 结构体指针中的 "dereferencing pointer to incomplete type”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960385/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com