I am trying to understand the unordered_map assignment, I get the following error: no matching function for call to std::pair<foo, foo>::pair(), according to the doc for unordered_map operator[]:
If k does not match the key of any element in the container, the function inserts a new element with that key and returns a reference to its mapped value.
So I am trying to assign an object (from make_pair) to this reference, which I am guessing is not allowed. However with the pair<int,int>, it works, then I am wondering if I must declare some other operators for foo to make this work.
#include <bits/stdc++.h>
using namespace std;
struct foo {
int n;
foo(int n): n(n) {};
};
int main(){
unordered_map<int, pair<foo,foo>> m;
//m[3] = make_pair(foo(1),foo(2)); <--- error here
unordered_map<int, pair<int,int>> ii;
ii[3] = make_pair(1,2);
}