Article directory
1. Naming conflicts
Because we included the <stdlib.h> header file, which contains the rand function, the compiler does not know whether you want to print the global variable rand or the rand function.
We defined a namespace A, and the compilation passed at this time, and the address of the rand function is output here.
Two, namespace namespace
1. Namespaces can store variables, structures, classes, and functions
namespace B
{
int a = 10;
void test()
{
cout << "hello world" << endl;
}
struct S {
};
class C {
};
}
2. The namespace must be declared in the global scope
We defined a namespace C in the local scope and reported an error.
3. Namespaces can nest namespaces
namespace D
{
int a = 10;
namespace E
{
int a = 10;
}
}