簡體   English   中英

使用typedef結構時出現未知類型錯誤

[英]Unkown type error when using typedef struct

我知道有很多問題要問,但是我已經看了很多,但我仍然不知道是什么問題。 一定是一個簡單的錯誤,但是我將此結構聲明和使用與在同一項目中使用的另一個結構聲明(沒有錯誤)進行了比較,它們對我來說看起來是相同的。

我在trie.h中聲明了這個結構:

#ifndef TRIE_H
#define TRIE_H

#include "fw.h"
#include "linked.h"

#define ALPHABET_SIZE 26

typedef struct T_node
{
   /* number of times this word has been found 
      (stored at end of word) */
   int freq;
   /* is_end is true if this T_node is the end of a word 
      in which case it */
   int is_end;
   /* each node points to an array of T_nodes
      depending on what letter comes next */
   struct T_node *next[ALPHABET_SIZE];
} T_node;

int add_word(T_node *root, char *word);
T_node *create_node(void);
void max_freqs(T_node *root, int num, List *freq_words, char *word,
               int word_len, int i);
void free_trie(T_node *root);

#endif

我在fw.h中使用它:

#ifndef FW_H
#define FW_H

#include <stdio.h>

#include "trie.h"

#define FALSE 0
#define TRUE 1

int read_file(FILE *in, T_node *root);
char *read_long_word(FILE *in);

#endif

我得到這個錯誤:

In file included from trie.h:4:0,
             from trie.c:5:
fw.h:11:25: error: unknown type name T_node
 int read_file(FILE *in, T_node *root);
                         ^

編輯:我不認為這是鏈接的問題的重復。 如果您查看的是最上面的答案,則似乎所提供的結構與我的T_node當前所使用的格式相同。而且,我沒有得到與該問題相同的錯誤。

錯誤訊息

In file included from trie.h:4:0,
             from trie.c:5:
fw.h:11:25: error: unknown type name T_node
 int read_file(FILE *in, T_node *root);
                         ^

trie.c包括trie.h ,其中包括fw.h

但是我們也看到fw.h包含trie.h 因此,我們有一個完整的圈子。


如果可能,使用前向聲明的struct int read_file(FILE *in, struct T_node *root); 並從fw.h刪除trie.h include。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM