The answer is the first one but I don't know why. Can anybody analyse each one?
Asked
Active
Viewed 44 times
-2

user7487638
- 151
- 8
-
1What do you mean you don't know why? Do you know what `multimap
` means? Now substitute `K` and `T`... – Kerrek SB Feb 20 '17 at 00:11 -
@KerrekSB, I know that k is key, and T is value. But the first one is not complete, it didn't give value but directrly give the operation of comparison. – user7487638 Feb 20 '17 at 03:27
-
Deep breath, clear mind: `K = string`, `T = greater
`... – Kerrek SB Feb 20 '17 at 10:18 -
@KerrekSB, Thank you! – user7487638 Feb 20 '17 at 13:27
1 Answers
1
The problem with the third example is that we are trying to insert not a pair, which should be the object inserted.Correct way to do this can be:
multimap<string, double> mp2;
mp2.insert({"ok", 3.14});
The second one is wrong becuse the key is of type string
while the third parameter, comparator, is for int
.
The first one is syntactically right and will be compiled succesfully, though it is quite weird.

zovube
- 46
- 7
-
Thanks for your answer. It's really helpful. But one thing Im not clear. The first one is not complete, it didn't give value but give key and then directrly give the operation of comparison. is that right? – user7487638 Feb 20 '17 at 03:30
-
as @KerrekSB said, here we have `value = std::greater
`, and where is no operation of comparison in this example, because it has only two arguments : the first : `key` and the second : `value`. – zovube Feb 20 '17 at 11:31 -