Why can't "transform(s.begin(),s.end(),s.begin(),tolower)" be complied successfully?

liu picture liu · Apr 4, 2011 · Viewed 25.5k times · Source

Given the code:

#include <iostream>
#include <cctype>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
     string s("ABCDEFGHIJKL");
     transform(s.begin(),s.end(),s.begin(),tolower);
     cout<<s<<endl;
}

I get the error:

No matching function for call to transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unresolved overloaded function type>)

What does "unresolved overloaded function type" mean?

If I replace the tolower with a function I wrote, it no longer errors.

Answer

davka picture davka · Apr 4, 2011

Try using ::tolower. This fixed the problem for me.