error: no matching function for call to ‘ptr_fun()’

下面这段代码会报错:报错信息为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;
}

 

你可能感兴趣的:(function)