std:findを使用して、std::list内の要素を取得するための検索関数を作成しようとしています。しかし、私はこの男に関して、検索アルゴリズムの3番目のパラメーターで立ち往生しています。stlリストで要素を検索する方法は?演算子==をかなりオーバーロードしましたが、それでもstd::findでは機能しないようです。
これは私のコードです:
class Node
{
string word;
int count;
public:
Node(string _word) :word(_word), count(0) {}
~Node() {}
const string& getWord() const{
return word;
}
bool operator == (const Node& other) const {
return (this->word.compare(other.word) == 0);
}
};
const Node &getNode(const list<Node> &nodes, const string &word){
list<Node>::iterator itr;
itr = find(nodes.begin(), nodes.end(), new Node(word)); <-- no viable overload '='
return *itr;
}
私は今その問題に夢中になっています、私にいくつかのヒントを提案してください。ありがとう