Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. std::map or stdex:hash_map

std::map or stdex:hash_map

Scheduled Pinned Locked Moved C / C++ / MFC
c++cryptographyhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Swinefeaster
    wrote on last edited by
    #1

    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... :(

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups