The whole point of multimap is that you can have multiple values at the same key. Keeping that in mind, what is mp[0]
supposed to mean?
In std::map<>
and std::unordered_map<>
it simply means "the value at that key", no sweat. But for std::multimap<>
it can't be that simple.
If mp[0]
were to return something when using multimap
, it would have to be some exotic proxy object that loosely refers to the "list" of items at that particular key, and that would become confusing fast, especially since the other map types just return a simple reference. It's simpler to just not have that operator altogether.
If you want to insert an item in a multimap, use insert()
like you've been doing. That also works fine for regular maps by the way, and is actually slightly cleaner if you know you are doing an insertion, as opposed to potentially replacing an already present element at that key.
mp.insert(0, -1);
I'd encourage you to refer to the documentation of map and multimap for specific details of what each of these containers can and cannot do.