Just use ::toupper
instead of std::toupper
. That is, toupper
defined in the global namespace, instead of the one defined in std
namespace.
std::transform(s.begin(), s.end(), std::back_inserter(out), ::toupper);
Its working : http://ideone.com/XURh7
Reason why your code is not working : there is another overloaded function toupper
in the namespace std
which is causing problem when resolving the name, because compiler is unable to decide which overload you're referring to, when you simply pass std::toupper
. That is why the compiler is saying unresolved overloaded function type
in the error message, which indicates the presence of overload(s).
So to help the compiler in resolving to the correct overload, you've to cast std::toupper
as
(int (*)(int))std::toupper
That is, the following would work:
//see the last argument, how it is casted to appropriate type
std::transform(s.begin(), s.end(), std::back_inserter(out),(int (*)(int))std::toupper);
Check it out yourself: http://ideone.com/8A6iV
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…