0

I have a C++ code, and it's giving me the following error:

Error   3   error C2338: The C++ Standard doesn't provide a hash for this type. c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstddef  238 1   Kruskal

It isn't referring me to a specific line in my code so I have no idea what to check. I googled this error and found that it has something to do with strings used in an unordered_map. However, while I do in fact use a few unordered_maps in my code, I don't have any strings.

Just in case this helps, these are my maps:

unordered_map<int, pair<int,int>> map_idx_cell;
unordered_map<pair<int,int>,int> map_cell_idx;

Does anyone have any idea what this could mean?

Cheshie
  • 2,777
  • 6
  • 32
  • 51
  • @tux3 - thanks for the link. It indeed looks like a similar issue, but I've read the answer there a few times and I don't get it. I wonder if it would be very rude of me to ask you to please explain it...? – Cheshie Mar 03 '15 at 21:35
  • 2
    unordered_map organizes elements based on their hashes internally. [A hash is essentially a number](https://en.wikipedia.org/wiki/Hash_function) that unordered_map computes for each key, but there's a different way to compute it for every *type*. The problem is that unordered_map doesn't know how to compute the hash of a std::pair. You need to tell it how to do that, or use a std::map instead. – tux3 Mar 03 '15 at 21:39
  • OK, thanks. Assuming that the only stuff I'm doing with the hash_table is store data, retrieve data, and iterate on it - does it change anything if I switch from an `unordered_map` to a `map`? (I don't know what the difference is). – Cheshie Mar 03 '15 at 21:46
  • 1
    std::map doesn't have quite the same performance, but if you switch to a map it should "just work". std::map doesn't use hashes, it uses comparisons to organize elements instead. – tux3 Mar 03 '15 at 21:48

0 Answers0