(C++) No matching function for call to 'ptr\_fun'
February 24, 2017 · View on GitHub
(C++) No matching function for call to 'ptr_fun'
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
#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; }