E
Eric Lilja
Hello, consider this program:
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
int
main()
{
std::string s = "HEJ";
std::transform (s.begin(), s.end(), s.begin(), std::tolower);
std::cout << "s: " << s << std::endl;
}
It doesn't compile, I get:
$ make
g++ -Wall -W -ansi -pedantic -g -c -o issue.o issue.cpp
issue.cpp: In function `int main()':
issue.cpp:10: 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> > >, <unknown type>)'
make: *** [issue.o] Error 1
¨
*but*, if I change the call to std::transform to
std::transform (s.begin(), s.end(), s.begin(), ::tolower);
(i.e., I pass ::tolower instead of std::tolower)
it compiles cleanly and produces the expected output when run. So it
works with the tolower that lives in the global namespace, why?
Is this the correct behaviour? Someone said that the first version
compiles cleanly on visual studio (unknown version) but I haven't had
the chance to try myself.
/ Eric
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
int
main()
{
std::string s = "HEJ";
std::transform (s.begin(), s.end(), s.begin(), std::tolower);
std::cout << "s: " << s << std::endl;
}
It doesn't compile, I get:
$ make
g++ -Wall -W -ansi -pedantic -g -c -o issue.o issue.cpp
issue.cpp: In function `int main()':
issue.cpp:10: 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> > >, <unknown type>)'
make: *** [issue.o] Error 1
¨
*but*, if I change the call to std::transform to
std::transform (s.begin(), s.end(), s.begin(), ::tolower);
(i.e., I pass ::tolower instead of std::tolower)
it compiles cleanly and produces the expected output when run. So it
works with the tolower that lives in the global namespace, why?
Is this the correct behaviour? Someone said that the first version
compiles cleanly on visual studio (unknown version) but I haven't had
the chance to try myself.
/ Eric