Risks of using namespace

It is risky to use “using namespace” because sometimes in a library two namespaces have different methods with same names. Therefore, compiler won’t know about which method you are talking about. In addition to this, when you show your work to other programmers or when u reread the code, it will be much easier to know which namespace you are using at that part of the code.

Yes that seems about right! At least how I also interpreted it.

Now I ask myself; Can you use a namespace and then halfway the cpp. file change it to another namespace?
So you would declare that "From this point I will use (and cout now means “destroy all humans”).
I mean like we are using curly brackets to enclose parts of code, maybe we can do the same with this?

What I am asking is probably not possible, but I am just curious here. I don’t mind using std:: for this :wink:

Privacy & Terms