したがって、ファイルindex.hでクラス「index」を次のように宣言しました。
#ifndef INDEX_H
#define INDEX_H
#include <iostream>
#include <sstream>
#include "word.h"
#include "heap.h"
using namespace std;
class index
{
public:
index();
~index();
index(const index &other);
index& operator = (const index &other);
void push(word<string> w);
word<string> pop();
private:
heap<word<string> > orchard[26];
void nukem();
void copy(const index &other);
};
#endif
そしてその後の定義:
#include "index.h"
index::index()
{}
index::~index()
{
nukem();
}
index::index(const index &other)
{
copy(other);
}
index& index::operator = (const index &other)
{
if(this != &other)
copy(other);
return *this;
}
void index::push(word<string> w)
{
orchard[w.data[0]]<<w;
}
word<string> index::pop()
{
word<string> popped;
int i = 0;
for(; orchard[i].empty(); i++);
orchard[i]>>popped;
return popped;
}
void index::nukem()
{
for(int i = 0; i < 26; i++)
orchard[i].clear();
}
void index::copy(const index &other)
{
for(int i = 0; i < 26; i++)
orchard[i] = other.orchard[i];
}
代入演算子の定義で、xcode から次のコンパイラ エラーが発生します。
「&」トークンの前にコンストラクタ、デストラクタ、または型変換が必要です
型の問題だと思ったので、「&」を削除して再コンパイルしようとすると、同じ行に次のエラーが表示されました。
「インデックス」はタイプではありません
どちらのエラーも、次のコードの最初の行に表示されます。
index& index::operator = (const index &other)
{
if(this != &other)
copy(other);
return *this;
}
index がヘッダー ファイルで宣言された型であることをコンパイラが認識しないのはなぜですか? 私が書いた以前のクラスを振り返りましたが、どこが間違っているのかわかりません。おそらく骨頭の間違いだと思いますが、見当たりません。すべての助けに感謝します。