ERROR取消引用指针在C型不完全 [英] ERROR Dereferencing pointer to incomplete type in c

查看:221
本文介绍了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;
}


解决方案

  

意味着什么这个错误?


向前声明

  typedef结构_Dictionary_t *字典;

不提供线索,以什么会员结构_Dictionary_t 可能。

您不能使用 main_dict->大小除非定义结构是在$点可见C $℃。自定义的结构 dictionary.c ,它的定义是不可见的东西在的main.c


  

我怎样才能解决这个问题?


解决方案1 ​​

移动结构的定义.h文件。

解决方案2

提供的功能,使您可以获取和设置的成员结构

dictionary.h

 无效setDictionarySize(词典字典,INT大小);
INT getDictionarySize((词典字典);

在实现它们的 dictioary.c

的main.c :使用该功能。替换

  A = main_dict->大小;

  A = getDictionarySize(main_dict);

I Have this error: dereferencing pointer to incomplete type main_dict ->size = 0;

What means this error? How I can fix it?

dictionary.c

struct _Dictionary_t {  
  char **dict;
  int size;
};

Dictionary dict_new (void){

  Dictionary dict_new = NULL;
  dict_new = calloc(1,sizeof(struct _Dictionary_t));
  assert(dict_new != NULL);
  dict_new -> dict = NULL; 
  return (dict_new);
}

dictionary.h

typedef struct _Dictionary_t *Dictionary;

Dictionary dict_new (void);

main.c

int main(void){

  int a;
  main_dict = dict_new();
  a = main_dict->size;
  if(a == 0){
      printf("I'll be here if I fix the error \n")
  }    
  return 0;
}

解决方案

What means this error?

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.

How I can fix it?

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型不完全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆