0

Why can't I have a map with a pair as it's key?

 unordered_map <pair<int, int> , int> m1;

Later in my code I try to insert the items into the map by doing:

m1.emplace(make_pair(i,j), nums1[i] + nums2[j]);

But I still get an error saying I have a call to "an implicitly deleted default constructor"

Brodman
  • 1
  • 2
  • You can have a `pair` type as a key, *as long as it is orderable*. In other words, there must exist a function that can compare two `pair` types for the ordering you desire, e.g. less than or greater than, and maybe equality. – Thomas Matthews Mar 15 '22 at 17:20
  • @ThomasMatthews That would be true for a std::map, but he refers to an std::unordered_map which requires a hash function instead of a comparator. – gerum Mar 15 '22 at 21:44

0 Answers0