使用 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。这样我们就有了一个完整的圆圈。


如果可能,使用前向声明的结构 int read_file(FILE *in, struct T_node *root); 并从 fw.h.

中删除 trie.h 包含