std::map or stdex:hash_map
-
hi there, i'm trying to set up a hash map such as:
class ObserversByMessageMap :
public stdext::hash_map<messagekey,>
{};and i've got MessageKey defined with these operators:
bool operator==(const MessageKey& other)const; bool operator!=(const MessageKey& other)const; bool operator<(const MessageKey& other)const; bool operator>(const MessageKey& other)const; // Used for hashing. operator size\_t(void)const;
something doesn't work quite right however. i'm trying to do something like:
MessageObserverSet& observers = (\*m\_observersByMessageMap)\[key\]; observers.insert(observer);
but it appears that the map (either hash or map) seems to collide with a *different* key than what i expect, and therefore adds the observer to the wrong pre-existing key. i figured the operator==() is supposed to prevent that from happening, but it aint being called. instead the size_t hash is called and also the < operator, which i've defined as:
bool
MessageKey::operator<(const MessageKey& other)const
{
bool lessThan = false;if(m_messageId <= other.m_messageId)
{
if(m_objectId < other.m_objectId)
{
lessThan = true;
}
}return lessThan;
}since m_objectId is a nested object. any ideas? in mfc this kind of stuff worked no problem... :(