This is why using-directives in the global namespace (or any other inappropriately wide scope) are a bad idea. It's not just a matter of style; it can change the meaning of the code in subtle ways. See this question for a thorough discussion of the issues.
Almost certainly, your code uses names from the standard library without qualification, and those names are also declared in the global namespace. Thus, removing using namespace std;
changes the meaning of those unqualified names, rather than just making the code fail to compile.
These might be names from your code; or perhaps they are C library functions. Many (particularly those in <cmath>
) are overloaded for various types, where the C library itself only declares a single function. It's unspecified whether none, some, or all of these are dumped into the global namespace as well as namespace std
.
For example, you might have a function call
float angle = whatever;
float sine = sin(angle);
With using namespace std;
, this will select the overloaded float std::sin(float)
that you've dumped into the global namespace. Without it, depending on what the implementation chooses to do with the global namespace, it might still call that; or it might call double sin(float)
from the C library; or it might fail to compile.
In the case of GCC, it seems that the C library function, but not the C++ overloads, are dumped into the global namespace, as I discovered while answering this question.