Can somebody please explain the following:
$ cat test.cpp
#include <string>
std::string div;
$ g++ -c test.cpp
$ g++ -std=c++11 -c test.cpp
test.cpp:2:13: error: 'std::string div' redeclared as different kind of symbol
In file included from /usr/include/c++/4.7.1/cstdlib:66:0,
from /usr/include/c++/4.7.1/ext/string_conversions.h:37,
from /usr/include/c++/4.7.1/bits/basic_string.h:2814,
from /usr/include/c++/4.7.1/string:54,
from test.cpp:1:
/usr/include/stdlib.h:787:14: error: previous declaration of 'div_t div(int, int)'
$
Shouldn’t the div symbol be in std namespace also for C++11 mode? Or is it something specific to my system?
Every name in a
.hC stdlib header resides in the global namespace (obviously).Additionally, any
cHEADERC++ stdlib header will define the corresponding names fromHEADER.hin thestdnamespace, but is also allowed to have them in the global namespace (so they can just doand be done with it).
§D.5 [depr.c.headers]As you can see, the same is also true the other way around (
<HEADER.h>may introduces names to thestdnamespace, as if), which makes the whole distinction between those headers rather… useless, really.