本文介绍了ERROR取消引用指针在C型不完全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的错误:提领指向不完全类型main_dict - >大小= 0;
意味着什么这个错误?我怎样才能解决这个问题?
dictionary.c
结构_Dictionary_t {
焦炭**字典;
INT大小;
};字典dict_new(无效){ 字典dict_new = NULL;
dict_new =释放calloc(1,sizeof的(结构_Dictionary_t));
断言(dict_new!= NULL);
dict_new - >字典= NULL;
回报(dict_new);
}
dictionary.h
typedef结构_Dictionary_t *字典;字典dict_new(无效);
的main.c
INT主要(无效){ int类型的;
main_dict = dict_new();
A = main_dict->大小;
如果(A == 0){
的printf(我会在这里,如果我修正错误。\\ n)
}
返回0;
}
解决方案
The forward declaration
typedef struct _Dictionary_t *Dictionary;
doesn't give a clue as to what members struct _Dictionary_t
might have.
You cannot use main_dict->size
unless the definition of struct
is visible at that point in the code. Since the definition of the struct
is in dictionary.c
, its definition is not visible to anything in main.c
.
Solution 1
Move the definition of the struct
to the .h file.
Solution 2
Provide functions that allow you to get and set the members of the struct
.
In dictionary.h:
void setDictionarySize(Dictionary dict, int size);
int getDictionarySize((Dictionary dict);
Implement them in dictioary.c.
Use the function in main.c. Replace
a = main_dict->size;
by
a = getDictionarySize(main_dict);
这篇关于ERROR取消引用指针在C型不完全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!