In adding a unordered_map type member to MyClass compilation error C2440 occurred
while operator== and hash_value() are already defined.
#include <unordered_map>
namespace MyNameSpace {
class MyClass {
public:
struct SomeArg { int x; int y; };
typedef void (MyClass::*FUNC)(MyClass*, MyClass::SomeArg);
struct SomeTuple { MyClass::FUNC a; int b; int c; };
void func(MyClass* myc, MyClass::SomeArg);
private:
// xfunctional(768): error C2440 'type cast' cannot convert 'SomeTuple' to 'size_t'
std::unordered_map<SomeTuple, int> someMap;
}; // end of MyClass
bool operator ==(const SomeTuple& a, const SomeTuple& b);
std::size_t hash_value(const MyClass::SomeTuple& t);
}
namespace std { // already tried moving here
//bool operator ==(const SomeTuple& a, const SomeTuple& b) {
// return (a.a==b.a && a.b==b.b && a.c==b.c);
//}
//size_t hash_value(const MyNameSpace::MyClass::SomeTuple& t) {
// size_t seed=0; boost::hash_combine(seed, t.x); boost::hash_combine(seed, t.y);
//}
}
What am I missing?
It’s not
boost. You should specializestd::hashfor your type, or give predicate tomap.If your
SomeTupleis not in class, in whichunordered_map, whereKeyisSomeTuple, is created – it’s simple, but in other case – it seems to me impossible.