what everyone seems to be failing to realize is that even when a "using namespace std" declaration is employed in the global scope, a member of a child scope may still be called by any of the names defined in the global scope. child scope names have precedence over parent scope names. take the following code for example:
the variable called "string" in main() does not conflict with std::string, because the C++ compiler takes any unqualified identifier to mean the one defined in the nearest scope.Code:#include <iostream> #include <string> using namespace std; int main(void) { char* string = nullptr; return 0; }
even the following code is valid:
I have confirmed this behavior on both G++ 4.5.1 and VC++ 2010.Code:#include <iostream> #include <string> using namespace std; int main(void) { typedef char* string; string s = nullptr; return 0; }