不完整的类型,正向声明

incomplete type, forward declaration

本文关键字:声明 类型      更新时间:2023-10-16

我只是在学习C ,我遇到了很多问题。目前,我正在尝试用堆和一个标签实现频率队列,因此我正在尝试为哈希表条目和堆条目制作结构。我所做的是...

  1 #include<iostream>
  2 #include<string>
  3 #include "freqq.h"
  4
  5 using namespace std;
  6
  7 
  8 
  9
 10 struct _hashEntry {
 11   string word;
 12   int heapPstn;
 13 };
 14
 15 struct _heapEntry {
 16   int frequency;
 17   hashEntry* wordInHash;
 18 };
^^ the .cpp, 
 1 #define FREQQ_H_
  2 #include <string>
  3
  4 using namespace std;
  5
  6 class FreqQ {
  7  public:
  8   struct _heapEntry;
  9   typedef struct _heapEntry heapEntry;
 10
 11   struct _hashEntry;
 12   typedef struct _hashEntry hashEntry;
 13

^^ .h。为了简单起见,我已经消除了其他方法。

我遇到了错误不完整类型的使用freqq :: _ hepentry -hepentry-使用无效的使用freqq.h:8:10:错误:freqq :: _hepentryâ

的前向声明

我无法弄清楚为什么我的一生。

任何想法??

谢谢!

我不明白。您正在定义.cpp中的_hashEntry_heapEntry结构?

将结构声明移至class FreqQ声明之前的.h,其中使用了结构。