“不允许指针指向不完整的类类型”问题出在哪?

codemonkey112 2019-05-13 02:55:37
最近在学习一个C语言的项目时,发现结构体和类型定义分别放在不同的.h头文件中,我试着自己定义一个类型,总是出现“不允许指针指向不完整的类类型”的问题,如下

//type_orgraph.h

typedef struct edge EDGEINFO;

//struct_orgraph.h

#include "type_orgraph.h"
struct edge
{
int time;
double cost;
bool conn;
};

//orgraph.h

#include type_orgraph.h

//orgraph.c

#include type_orgraph.h
#include orgraph.h
static SCIP_RETCODE Test(EDGELINK* edge)
{
int head = edge->head;//这里提示 “不允许指针指向不完整的类类型”
}

这是什么原因呢?我看之前的项目里,也是这么个操作就没问题,我的问题原因出在哪里呢?
谢谢!
...全文
2082 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2019-05-13
  • 打赏
  • 举报
回复
// orgraph.c 中只包含了 type_orgraph.h 其中没有结构体实体定义

#include "type_orgraph.h"
#include "orgraph.h"

// orgraph.c 中 type_orgraph.h 改成 struct_orgraph.h

#include "struct_orgraph.h"
#include "orgraph.h"
lin5161678 2019-05-13
  • 打赏
  • 举报
回复
//orgraph.h

#include type_orgraph.h

//orgraph.c

#include type_orgraph.h
#include orgraph.h
相当于 #include type_orgraph.h #include type_orgraph.h 相当于 typedef struct edgelink EDGELINK; typedef struct edgelink EDGELINK; 没找到结构体定义 所以提示不完整类型
lin5161678 2019-05-13
  • 打赏
  • 举报
回复
引用 4 楼 NIL_ 的回复:
先定义结构体 再typedef ,也就是说你应该在type_orgraph.h中 include struct_orgraph.h
这个没影响
拥抱Linux 2019-05-13
  • 打赏
  • 举报
回复
严重怀疑 头文件 「 orgraph.h 」的内容 不是 「 #include type_orgraph.h 」,而是

#inclulde "struct_orgraph.h"
636f6c696e 2019-05-13
  • 打赏
  • 举报
回复
一般是包含的其他头文件里包含了struct_XX.h 你自己好好想想,如果你没有指定包含,编译器怎么知道从哪里找?
引用 5 楼 codemonkey112 的回复:
[quote=引用 4 楼 NIL_ 的回复:] 先定义结构体 再typedef ,也就是说你应该在type_orgraph.h中 include struct_orgraph.h
以前我也是这么认为的,可是看之前的项目代码中并没有在type_XX.h中去 包含struct_XX.h文件啊,依然可以运行,可能 是什么原因呢?都写的是在struct_XX.h中 #include "type_XX.h"文件,很奇怪啊[/quote]
自信男孩 2019-05-13
  • 打赏
  • 举报
回复
是否包含了声明结构体类型的头文件,建议检查一下。或者直接把你的代码分别贴出来。
拥抱Linux 2019-05-13
  • 打赏
  • 举报
回复
没有包含 "struct_orgraph.h" 文件
codemonkey112 2019-05-13
  • 打赏
  • 举报
回复
引用 4 楼 NIL_ 的回复:
先定义结构体 再typedef ,也就是说你应该在type_orgraph.h中 include struct_orgraph.h


以前我也是这么认为的,可是看之前的项目代码中并没有在type_XX.h中去 包含struct_XX.h文件啊,依然可以运行,可能 是什么原因呢?都写的是在struct_XX.h中 #include "type_XX.h"文件,很奇怪啊
NIL_ 2019-05-13
  • 打赏
  • 举报
回复
先定义结构体 再typedef ,也就是说你应该在type_orgraph.h中 include struct_orgraph.h
拥抱Linux 2019-05-13
  • 打赏
  • 举报
回复
(1)从上面的代码,看不到 EDGELINK 的定义,不知道它是什么。
(2)把#include的头文件用双引号或者尖括号括起来吧。
codemonkey112 2019-05-13
  • 打赏
  • 举报
回复
不好意思写错了:)

//type_orgraph.h

typedef struct edgelink EDGELINK;

//struct_orgraph.h

#include "type_orgraph.h"
struct edgelink
{
int head;
int tail;
EDGELINK* hlink_next;
EDGELINK* tlink_next;
};

//orgraph.h

#include type_orgraph.h

//orgraph.c

#include type_orgraph.h
#include orgraph.h
static SCIP_RETCODE Test(EDGELINK* edge)
{
int head = edge->head;//这里提示 “不允许指针指向不完整的类类型”
}
自信男孩 2019-05-13
  • 打赏
  • 举报
回复
EDGELINK和EDGEINFO的区别,建议一一比对。

另外,struct edge里也没有head成员。

两处矛盾,不知道那个地方是有问题,你自己看一下

70,027

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧