簡體   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