1

私はちょうど 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 . 簡単にするために、他の方法は省略しました。

不完全なタイプの無効な使用 âstruct FreqQ::_heapEntryâ freqq.h:8:10: error: forward declaration of âstruct FreqQ::_heapEntryâ というエラーが表示されます

そして、私は私の人生の理由を理解できません。

何か案は??

ありがとう!

4

1 に答える 1

2

理解できない。.cppで構造体_hashEntryと構造体を定義していますか?_heapEntry

構造体宣言を、構造体が使用される宣言の前の .h に移動しclass FreqQます。

于 2012-11-02T20:27:03.683 に答える