次のコードでエラーが発生しました
struct MapKey {
std::string x;
std::string y;
}
std::map<MapKey, int> m;
if (m.find(key) != m.end()) {
......
}
エラーが表示されます。
no match for "operator<" in '__x < __y'
問題は、MapKey に比較メソッドが必要なことだと思います。Mapkey 用にどのように実装できるか疑問に思っています。例えば、
struct MapKey {
bool operator<(const MapKey &key) const {
... what shall I put here? ...
}
std::string x;
std::string y;
}
ありがとう。