mercredi 23 novembre 2022

When I use sorting predicate for multimap, , an error will be reported when calling "count". Is this an official bug?

here is my code:

#include <iostream>
#include <map>
#include <string>
using namespace std;

template <typename T>
struct DescendingSort {
    bool operator () (const T key1, const T key2) {
        return (key1 > key2);
    }
};

int main()
{
    multimap<int, string, DescendingSort<int>> m;
    m.insert(make_pair(3, "three"));
    m.insert(make_pair(3, "drei"));

    cout << m.count(3) << "\n\n";  // error
    return 0;
}

If my code is wrong, where is the problem? (I run the code in c++11)

Aucun commentaire:

Enregistrer un commentaire