error: no matching function for call to ‘ptr_fun(<unresolved overloaded function type>)’

下面这段代码会报错:报错信息为error: no matching function for call to ‘ptr_fun(<unresolved overloaded function type>) 

#include <algorithm>

#include <cctype>
#include <string>

const std::string StrToUpper(std::string s)
{
  std::transform(s.begin(), s.end(), s.begin(),std::ptr_fun(std::toupper));
  return s;

}

Solution

 

Explicitly add the template parameters:

 

#include <algorithm>
#include <cctype>
#include <string>

//From http://www.richelbilderbeek.nl/CppStrToUpper.htm
const std::string StrToUpper(std::string s)
{
  std::transform(s.begin(), s.end(), s.begin(),std::ptr_fun<int,int>(std::toupper));
  return s;
}

 

原文地址:https://www.cnblogs.com/xuxm2007/p/1925218.html