Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7786411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:24:47+00:00 2026-06-01T20:24:47+00:00

I need to use an unordered_multimap for my Note objects and the keys will

  • 0

I need to use an unordered_multimap for my Note objects and the keys will be the measureNumber member of my objects. I’m trying to implement it as shown here but I’m stuck.

First off, I don’t understand why I have to overwrite the operator== before I can use it. I’m also confused about why I need a hash and how to implement it. In this example here, none of those two things is done.

So based on the first example, this is what I have:

class Note {
private:
    int measureNumber;
public:
    inline bool operator== (const Note &noteOne, const Note &noteTwo);
}

inline bool Note::operator ==(const Note& noteOne, const Note& noteTwo){
    return noteOne.measureNumber == noteTwo.measureNumber;
}

I don’t know how to implement the hash part though. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:24:48+00:00Added an answer on June 1, 2026 at 8:24 pm

    std::multimap is based on a sorted binary tree, which uses a less-than operation to sort the nodes.

    std::unordered_multimap is based on a hash table, which uses hash and equality operations to organize the nodes without sorting them.

    The sorting or hashing is based on the key values. If the objects are the keys, then you need to define these operations. If the keys are of predefined type like int or string, then you don’t need to worry about it.

    The problem with your pseudocode is that measureNumber is private, so the user of Note cannot easily specify the key to the map. I would recommend making measureNumber public or rethinking the design. (Is measure number really a good key value? I’m guessing this is musical notation.)

    std::multimap< int, Note > notes;
    Note myNote( e_sharp, /* octave */ 3, /* measure */ 5 );
    notes.insert( std::make_pair( myNote.measureNumber, myNote ) );
    

    The objects can be keys and values at the same time, if you use std::multiset or std::unordered_multiset, in which case you would want to define the operator overload (and possibly hash). If operator== (or operator<) is a member function, then the left-hand side becomes this and the right-hand side becomes the sole argument. Usually these functions should be non-member friends. So then you would have

    class Note {
    private:
        int measureNumber;
    public:
        friend bool operator< (const Note &noteOne, const Note &noteTwo);
    }
    
    inline bool operator <(const Note& noteOne, const Note& noteTwo){
        return noteOne.measureNumber < noteTwo.measureNumber;
    }
    

    This class could be used with std::multiset. To perform a basic lookup, you can construct a dummy object with uninitialized values except for measureNumber — this only works for simple object types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use something like get_or_create() but the problem is that I have
So, I need use this event so I can navigate trought blog posts. I
Need to use own imaged markers instead built-in pins. I have several questions. 1.
i need to use the animate property for a less than usual activity. i
I need to use scp update some directory at another server. It is similar
I need to use some classes inside the app_code folder of a website project
I need to use Twitter api from iPhone 3.0 (SDK 3.0). can i use
I need to use system-specific functions, e.g. ftello() (defined in stdio.h as per POSIX
I need to use a function inside of another function, how can I do
I need to use the SharePoint API in the following way in a PowerShell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.