Possible problems when using namespaces

Placing a “using namespace [namespace]” at the top of our code allows us to write code without having to specify the namespace with each method we write.

I.e. std::cout << “Hi”; turns into cout << “Hi”

Over time this will create code that is easier to read and faster to write.

However, when multiple using statements are placed in the same file there runs a risk of a namespace clash - which is where two or more namespaces have the same method name, and you cannot easily determine which namespace the method belongs to.

To remedy this, try naming methods so they won’t be easily repeated in other namespaces (yet still have names that make sense), or just specify the namespace when a clash will occur.

Privacy & Terms