I have a class with a name error_code. I use it as a key for std::mapand CMap(MFC). I can make it work for std::map, but not CMap. Can I find out how I can do this?
std::map<error_code, int> m;
m[error_code(123)] = 888;
// error C2440: 'type cast' : cannot convert from 'error_code' to 'DWORD_PTR'
CMap <error_code, error_code&, int, int& > m;
m[error_code(123)] = 888;
class error_code {
public:
error_code() : hi(0), lo(0) {}
error_code(unsigned __int64 lo) : hi(0), lo(lo) {}
error_code(unsigned __int64 hi, unsigned __int64 lo) : hi(hi), lo(lo) {}
error_code& operator|=(const error_code &e) {
this->hi |= e.hi;
this->lo |= e.lo;
return *this;
}
error_code& operator&=(const error_code &e) {
this->hi &= e.hi;
this->lo &= e.lo;
return *this;
}
bool operator==(const error_code& e) const {
return hi == e.hi && lo == e.lo;
}
bool operator!=(const error_code& e) const {
return hi != e.hi || lo != e.lo;
}
bool operator<(const error_code& e) const {
if (hi == e.hi) {
return lo < e.lo;
}
return hi < e.hi;
}
unsigned __int64 hi;
unsigned __int64 lo;
};
source
share