A nested namespace is a namespace that is defined within another namespace. It allows
for organization and grouping of related namespaces.
#include <iostream>
namespace A {
int x = 1;
namespace B {
int y = 2;
namespace C {
int z = 3;
}
}
}
int main() {
int a = A::x;
int b = A::B::y;
int c = A::B::C::z;
std::cout << "a: " << a << std::endl;
std::cout << "b: " << b << std::endl;
std::cout << "c: " << c << std::endl;
return 0;
}
In this example, namespace "A" contains an integer variable x and another namespace
"B" which contains an integer variable y and it contain another namespace "C" which
contains an integer variable z.You can access the variables of nested namespace by
using the scope resolution operator "::" . In this case, to access the variable y
which is in namespace B, we have to use A::B::y and to access the variable z which
is in namespace C, we have to use A::B::C::z.
This way you can organize your code in a more readable and maintainable way.
To embed this project on your website, copy the following code and paste it into your website's HTML: