Umm what? I'm having difficulty with this section

Hey everyone, I’m completely new to coding and was following along rather well with this section until we got to the exercise about getting rid of std:: and explaining why multiple namespaces are a bad thing. Frankly I’m unsure what the difference is between a library and a namespace. I’ve listen to the video 3-4 times and I’m still lost.


Hey PJSkittles,

They remove the std:: simply to show you that it is possible to use the (using namespace std;) the reason it is a bad idea to use multiple namespace is because in the future while you are writing your code it is better for your sanity to use std:: or whatever namespace you desire to specifically show in the code that you are using that name space. But if you use multiple (using namespace) you will run into the problem of not knowing what the namespace of the function you are currently using is. I know it sounds all rambled but personally I never use (using namespace) because it confuses you later on when you are like over a few hundred lines of code in. P.S also it looks better when people look at your code to show them what namespace you are actually using at that given point of the code.

Hope that helps!

I hope I can help - I am new to this too. My understanding is that a namespace is kind of like a secret short name for a commonly used term/instruction. Each collection of these secret names is called a library. So the library iostream has a whole bunch of its own secret names (namespaces) that when you use them shorten the amount of typing you have to do and sometimes have instructions hidden in them eg: cout which stands for character output and tells the computer to output the following words…
The library String will have its own collection of namespaces (secret words). We have imported both libraries.
Sadly the authors of each may have used the same secret word to mean completely different things.
When we use a namespace - we need to say which library we are referencing so that it is clear which namespace and library to use.
If you type at the top of the document that the namespace is going to be standard (you are assuming that the libraries will have only unique namespaces and no duplicates). That instruction then applies to the rest of the document and this will save a heap of time and typing.
If your assumption is wrong however - and there are duplicate namespaces then your program wont know which to use and you will have an error (that can be quite hard to find).

@ everyone who already understands this - is this correct?
and @PJSkittles - Please let me know if that helps

1 Like

Thanks everyone, I think I get it now. Its basically a fancy way of saying its a folder that contains a set of call-outs for the compiler to reference. The downside is if there are multiple namespaces that contain the same call-out, the compiler wont know which to pull from?

Privacy & Terms