Why is using namespace std bad practice?
I have seen the statement, "Using namespace std is bad practice". But every time I try to find out I get really confusing answers that make no sense to me. Can someone give me a simple answer as to why it is?
Let's say you have two namespaces,
bar. Let's say foo has function named
bar has a function with the same name. Now let's say you do this:
using namespace foo; using namespace bar;
Now you have a naming conflict and the compiler complains about it.
using namespace pretty much goes against the meaning of namespaces.
Clutter, pretty much. Namespaces are useful for organising stuff, so if you pull everything out of their namespaces (with the
using namespace directive) into the global namespace, it becomes cluttered, and you lose your organisation. In addition, if two namespaces have members with the same name (like
bar::Baz()), using the
using namespace directive causes them to break each other in the same way as calling two functions the same name would.