liu liu - 2 months ago 12
C++ Question

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

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

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