Why using a namespace can be bad

One reason why using a namespace can be bad is that when another programmer is looking at your code they might not know what namespace the object comes from if you’re using multiple namespaces. It can also cause an issue if the object is referenced in more than one namespace.

1 Like

I saw a suggestion which might help limit the damage of a namespace collision:
similar to how in Python you would:
from math import sin
in C++ you can do this:
using std::cout;
and it doesn’t include the entire std library.

4 Likes

Hey, thanks for letting me know this!

using Namespace can be bad because:

  1. Can create conflicts with other libraries that contains the same string for other reasons.
  2. Can promote poor programming due to the need for short cuts.

For my code exercise, I used the following:
using std::cout;
using std::endl;

Privacy & Terms