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, but why the compiler cannot tell? Is it because how function
type works underneath? Will it be fixed in later standard maybe?
Thanks.
Aucun commentaire:
Enregistrer un commentaire