Korzystanie z STL C++ hash_map ...Jak używać stdext :: hash_map, gdzie klucz jest obiektem niestandardowym?
class MyKeyObject
{
std::string str1;
std::string str2;
bool operator==(...) { this.str1 == that.str1 ... }
};
class MyData
{
std::string data1;
int data2;
std::string etcetc;
};
tak ...
MyKeyObject a = MyKeyObject(...);
MyData b = MyData(...);
stdext::hash_map <MyKeyObject, MyData> _myDataHashMap;
_myDataHashMap[ a ] = b;
dostaję cały ciężar błędów. Oto trzy pierwsze ...
Error 1 error C2784: „bool std :: operator < (const std :: _ Drzewo < _Traits> &, const std :: _ drzewa < _Traits> &) 'nie może wydedukować szablonu argument 'const std :: _ drzewa < _Traits> &' z 'const MyKeyObject' C: \ Program Files \ Microsoft visual studio 8 \ VC \ include \ funkcjonalną 143
Błąd 2 error C2784: 'bool std :: operator < (const std :: basic_string < _Elem, _Traits, _Alloc> &, const _Elem *)': nie mogła wywnioskować szablonu argument „const std : basic_string < _Elem, _Traits, _Alloc> & 'od 'const wielozadaniowych :: MyKeyObject' C: \ Program Files \ Microsoft visual studio 8 \ VC \ include \ funkcjonalną 143
błąd 3 błędu C2784:' bool std :: operator < (Const _Elem *, const std :: basic_string < _Elem, _Traits, _Alloc> &)”: nie można wywnioskować szablon argumentem dla 'const _Elem *' od 'const MyDataObject' C: \ Program Files \ Microsoft wizualny studio 8 \ VC \ include \ funkcjonalny 143
...
Jeżeli ustawić klucz do czegoś prostego jak int wszystko jest dobrze.
Co robię źle ?! Może muszę coś zrobić z szablonami?
Czy istnieje lepszy (szybszy?) Sposób dostępu do danych przy użyciu niestandardowego obiektu klucza, takiego jak ten?
'hash_map' jest stary rozszerzenie. Użyj "unordered_map" tr1 lub Boost. – GManNickG