From: Oscar F. <of...@wa...> - 2002-09-17 22:37:07
|
"Stephen M. Webb" <ste...@cr...> writes: > On September 17, 2002 03:28 pm, Oscar Fuentes wrote: > > > > > > This is indeed the cause of the OP's problem, > > > > I don't think so. As the message you responded says, the problem is > > the existence of two 'tolower' functions, one being > > > > int tolower(int); // which is the same than int std::tolower(int) > > > > and the other an instantiation of > > > > template </*...*/> charT tolower(charT, const locale&); > > > > which is introduced by <iostream>. If you omit <iostream>, the > > problem disappears. > > Ah, yes, you're right. Given all the tolower functions, either the > parameters don't match (std::tolower(char, std::locale&)) or an > implicit conversion is required (std::tolower(char) hoisted from ::), > which is disallowed by the overload resolution rules. The problem is that 'transform' declaration is underspecified, possibly because of limitations of C++. The 'transform' declaration just says that its fourth parameter is "something". The compiler has no chance for resolving overloads: #include <algorithm> #include <string> int foo(int v, int w) { return v+w; } char foo(char v) { return v; } int main() { std::string s("hello"); std::transform( s.begin(), s.end(), s.begin(), foo); } The compiler is unable to choose the appropriate overload. How can it know? > In other words, this is a legitimate bug in the OP's code because you > can't use implicit overload resultion to distinguish between the 21.4 > tolower() and the 22.1.3 tolower() functions. > > Using ::tolower() just happens to work because of the GCC standard > library implementation hoising global namespace names from the C > library into std::. Exactly. > This is in fact a (mostly harmless) bug in the GCC implementation. -- Oscar |