In C++ primer 5th edition p 578 it is said that
We cannot store the name of an overloaded function in an object of type function
The provided code is :
int add (int i, int j) {return i+j;}
Sales_data add (const Sales_data&, const Sales_data&);
map <string, function <int(int, int)>>binops;
binops.insert ({"+", add}); // error : which add ?
What I do not understand is why the compiler cannot tell which add function to insert into the given map : the add
which takes Sales_data&
as argument does not match the function signature the map was created with and I would expect the compiler to be able to tell that the function to insert into the map is int add (int i, intj) {return i+j;}
Why does the compiler not know it ?