[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tolower - std namespace?
From: |
Taras_96 |
Subject: |
Re: tolower - std namespace? |
Date: |
Wed, 19 Mar 2008 03:41:40 -0700 (PDT) |
User-agent: |
G2/1.0 |
On Mar 15, 5:12 pm, Thomas Maeder <mae...@glue.ch> wrote:
>
> "works" and "doesn't work" are very vague. What error messsage do you
> get?
>
....
> Unfortunately, the situation is more complicated:
> - <cctype> declares the 1 argument version of std::tolower()
> - <locale> declares the 2 argument version of std::tolower()
> - in C++, <ctype.h> works like <cctype> but adds a using declaration
> for std::tolower in the global namespace
>
> And in reality, C++ implemetations often don't implement the 3rd item
> correctly. So the best thing IMHO is to not #include <ctype.h> in new
> code and rely on the tolower() overloads in namespace std.
>
.....
>
> > So, if the problem *is* because the std::tolower version takes 2
> > arguments (and not one), this lead me to ask why it works in gcc?
>
> Please post a minimal, complete program that demonstrates your
> problem. Without seeing what headers you #include, your audience can
> only make guesses.
Your reply clarifying the the 'versions' of the tolower function did
clarify this issue quite a bit.
I tried a number of things with some test code. The test code is:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
int main()
{
std::string tempString = "BLAH";
transform(tempString.begin(),tempString.end(),tempString.begin(),
(int(*)(int))std::tolower);
std::cout << tempString << std::endl;
}
I will alter the above code by:
1) Including <cctype>, then changing this to include <ctype.h>
2) Switching between std::tolower and tolower
1. As is:
--------------------
g++ compiled fine
MSV2008:tolower.cpp(10) : error C2039: 'tolower' : is not a member of
'std'
Where is 'tolower' being pulled in from for g++? I'm not including
cctype or ctype.h...
2. #include <cctype>, calling std::tolower
--------------------
g++ compiled fine
MSV2008 works fine
2. #include <cctype>, calling tolower
--------------------
g++ compiled fine
MSV2008 works fine
3. #include <ctype.h>, calling std::tolower
--------------------
g++ compiled fine
MSV2008: tolower.cpp(11) : error C2039: 'tolower' : is not a member of
'std'
It seems that including ctype.h is placing to lower into the global
namespace, but also hiding it from the std:: one?
4. #include <ctype.h>, calling tolower
--------------------
g++ compiled fine
MSV2008: works fine
As expected as ctype.h puts tolower into the global namespace
What are the reasons for these differences?