Namespace clash - easy

You could say:
using namespace std;
and then for example:
using namespace something;
Both of them could have a function named ‘cout’.

If you don’t specify exactly which cout of which namespace you want to use the compiler will be very confused and won’t accept it. Because there cant be multiple functions named cout.
So you have to specify infront of cout either ::std or ::something.

Hope I helped someone out guys! :wink:

1 Like

So the end word (for example std or your “something”) is irrelevant. If I wanted to, I could in fact write “using namespace chocolatebrownie;”, or am I thinking to wide here?

No, the end word is not irrelevant. It has to be an existing namespace, not just something random.

The std namespace or namespaces nested within it contains all C++ standard library types and functions. So that’s why that is so often seen, since it contains a lot of often used functions.

To use something like “using namespace chocolatebrownie;” somebody would have had to define that namespace in a header-file or something like that.

Microsoft has some nice info at https://docs.microsoft.com/en-us/cpp/cpp/namespaces-cpp

Thanks dude, your explanation is clear and simple :muscle::grimacing:

Privacy & Terms