### Namespaces

Carbide supports namespaces, which provide the scope for identifiers. Listing 3.1 provides an example of how you define items in a namespace.

namespace NS
{
int foo();
void bar();
}

The above example defines an int variable named NS::foo and a function named NS::bar.

You can nest namespaces. For example, you can define an identifier as A::B::C::D::E where A, B, and C are nested namespaces and D is either another namespace or a class. You cannot use namespaces within class definitions.

You can rename namespaces for a module. For example:

namespace ENA = ExampleNamespaceAlpha;

creates a namespace alias called ENA for the original namespace ExampleNamespaceAlpha.

You can import items from a namespace. For example:

using namespace NS;

makes anything in NS visible in the current namespace without a qualifier. To limit the scope of an import, specify a single identifier. For example:

using NS::bar;

only exposes NS::bar as bar in the current space. This form of using is considered a declaration. So, the following statements:

using NS::foo;
int foo;

are not allowed because foo is being redeclared in the current namespace, thereby masking the foo imported from NS.