Namespaces are like packages in Java. They set a prefix for all variables/functions/classes defined inside.
The “using” command
There are two kinds of
- Using namespaces:
using namespace foo;
- Using particular variables/functions/classes:
You can define a namespace with no name, but only code in the same file can refer to stuff inside the unnamed namespace.
Technically, the compiler generates a random unique name for the unnamed namespace, and includes a
using statement with that name in the same file. So, an unnamed namespace is equivalent to:
No other file can refer to this namespace because you (as the programmer) don’t know what that random unique id is going to be.