|
-
June 22nd, 2010, 03:16 PM
#1
Multimap Key Issue
Hi-
I've got a multimap problem. The key for the multimap is a class with a few data members. I've overloaded the < operator so that key look up should take all of the relevant data members into consideration.
But what I am observing is that the look up seems to not be working...i.e. it is returning keys with slightly different data members.
Also, when I call erase on the multimap and pass the key I want used to erase the values, it is deleting values that don't exactly match the key.
Is there some other operator I need to overload as well?
Thanks!
-
June 22nd, 2010, 04:24 PM
#2
Re: Multimap Key Issue
It sounds like your '<' isn't working quite right.
Viggy
-
June 22nd, 2010, 04:25 PM
#3
Re: Multimap Key Issue
Oh, wait, you say 'multi-map'. Are you sure you're deleting the correct entry? A multi-map allows duplicate keys, but does not guarantee what order they will be in (other then they will all be grouped together, when you're iterating over the entries).
Viggy
-
June 22nd, 2010, 04:34 PM
#4
Re: Multimap Key Issue
I'm sure that I'm not deleting the correct entry. 
I am iterating over the keys, but one of the keys should not have been returned from the equal range, so its value is getting erased as well.
So is it normally just the < operator then that I have to change?
-
June 22nd, 2010, 04:46 PM
#5
Re: Multimap Key Issue
Yes, the std template library only uses '<' for map and set comparisons. If that's the case, then your '<' isn't correct. It must be antisymmetric (if x < y is true, then y < x must be false); transitive (if x < y and y < z, then x < z must be true); and it must be irreflexive (x < x is always false).
One of these conditions must not be being met.
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|