繁体   English   中英

找不到typedef的定义

[英]Can't find the definition of a typedef

我有我的file.h

#ifnotdef _FILE_H_
#define _FILE_H_
#include "lista2.h"
    struct texto{
        int col_cursor;
        int lin_cursor;
        lista2* texto;
        int tecla;
    };
    typedef struct texto Texto;  
#endif //_FILE_H_

而且我有我的file.c

#include "file.h"
#include "lista2.h"   

     void recua_linha(Texto* t){
           if(!(t->texto->corrente == t->texto->primeiro))
             t->lin_cursor--;
    }   

lista2.h

#ifndef _LISTA2_H_
#define _LISTA2_H_
    typedef struct lista2 lista2;
    typedef struct elemento elemento;
#endif //_LISTA2_H_

lista2.c

#include "lista2.h"
    struct elemento{
        dado_t str;
        elemento* ant;
        elemento* prox;
    };

struct lista2{
    elemento* primeiro;
    elemento* ultimo;
    elemento* corrente;
};

但是当我尝试访问Texto任何成员时,我都会

Dereferencing pointer to incomplete type

我知道这意味着: 程序知道Type,但是看不到它的实现。 我只是不知道为什么或如何解决它。

Ps:我还需要访问main.c文件中的Texto .members。

从file.c中获取以下代码:

t->texto->corrente

tTexto结构。 现在,从file.h中,我们有以下内容:

lista2* texto;

Texto结构的成员。 现在我们必须看看lista2lista2知道什么。 我们必须查看file.c中包含的标题,即file.h和lista2.h。 第一个没有任何相关性。 但是第二个确实具有以下内容: typedef struct lista2 lista2; ,这很有帮助。 但是 ,您请求命名数据成员corrente ,但lista2.h不提供有关的数据成员的任何信息lista2 ,因此,你应该会收到类似的错误这样的:

错误:取消引用不完整类型的指针

因为所有file.c都知道它是在lista2.h中看到的typedef


为了做您想做的,您应该像这样修改lista2.h:

#ifndef _LISTA2_H_
#define _LISTA2_H_
// moved it here, in order to use just 'elemento'
typedef struct elemento elemento;
struct elemento {
  // I do not know what dato_t is...discarded
  elemento* ant;
  elemento* prox;
};

struct lista2 {
  elemento* primeiro;
  elemento* ultimo;
  elemento* corrente;
};

typedef struct lista2 lista2;
#endif //_LISTA2_H_

将lista2.c留空。 另请注意,我看不到为什么在结构之前添加选项卡(缩进从文件的第一列开始),因此我将其删除。

顺便说一句,在file.h中,也许您想更改此设置

#ifnotdef _FILE_H_

对此

#ifndef _FILE_H_

因为你应该收到这个

无效的预处理程序指令:ifnotdef

注意,为了从main()访问Texto ,您应该在主文件中包含file.h。


提示 :一个很好的习惯是使用一种社区可以在您的代码中(完全)理解的语言(英语!),并且,如果将来您需要为现实应用开发代码,则可能必须使用英语。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM