1

I am reading C++ primer and my question comes from 14.8.3 Callable Objects and function. In the Overloaded Functions and function section, it says:

We cannot (directly) store the name of an overloaded function in an object of type function:

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?

I believe it is quite obvious which add we want to add, at least for human I guess (there is only one call signature matches), but why the compiler cannot tell? Is it because how function type works underneath? Will it be fixed in later standard maybe?

Thanks.

Sean
  • 2,649
  • 3
  • 21
  • 27
  • Is http://stackoverflow.com/questions/30393285/stdfunction-fails-to-distinguish-overloaded-functions this what you are looking for? – Sniper Apr 28 '17 at 04:57

0 Answers0