Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) No matching function for call to 'ptr_fun'

 

Compile error.

 

 

 

 

 

Full error message

 

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

 

 

 

 

 

Cause

 

IDE: Qt Creator 1.2.1

Project type: Qt4 Console Application

Selected required modules: QtCore

Compiler: G++ 4.4.1

 

#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(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;
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict