samedi 25 août 2018

pair key for unorderd_map

#include <bits/stdc++.h>

std::unordered_map<std::pair<int,int>, int> mp;

int main()
{
    mp[make_pair(1, 2)]++;
}

when using the [] operator, I get this

 error: no match for ‘operator[]’ (operand types are ‘std::unordered_map<std::pair<int, int>, int>’ and ‘std::pair<int, int>’)

However, when doing the same with std::map, no error occurs. why? And how can I make it works with std::unorderd_m?

Aucun commentaire:

Enregistrer un commentaire