Ç - 取消引用指针不完全类型 [英] C - Dereferencing pointer to incomplete type
问题描述
我已经阅读了同样的错误在5个不同的问题,但我仍然无法找到什么是我的code中的问题。
I have read about 5 different questions on the same error, but I still can't find what's the problem with my code.
的main.c
int main(int argc, char** argv) {
//graph_t * g = graph_create(128); //I commented this line out to make sure graph_create was not causing this.
graph_t * g;
g->cap; //This line gives that error.
return 1;
}
.C
struct graph {
int cap;
int size;
};
.H
typedef struct graph graph_t;
谢谢!
推荐答案
您不能这样做,因为该结构在不同的源文件中定义。 typedef的整点是从你隐藏的数据。可能有功能,如 graph_cap
和 graph_size
,你可以调用返回的数据给你。
You can't do that since the struct is defined in a different source file. The whole point of the typedef is to hide the data from you. There are probably functions such as graph_cap
and graph_size
that you can call that will return the data for you.
如果这是你的code,你应该定义结构图
头文件中,使包括该头的所有文件都能够拥有的定义吧。
If this is your code, you should define struct graph
inside the header file so all files that that include this header will be able to have the definition of it.
这篇关于Ç - 取消引用指针不完全类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!