What is "namespace"

A namespace is an abstract delimiter (container) that provides a context for the items it stores (names, technical terms, concepts...), which allows a disambiguation for items that have the same name but reside in namespaces. As a distinct context is provided for each container, the meaning of a name may vary according to the namespace in which it belongs.

In an operating system, an example namespace is a directory, which has files and subdirectories that must have separate names.

In several programming languages, a namespace is a context for identifiers. A namespace cannot have two functions or variables with the same name. However, it is allowed in programming languages to open namespaces within other namespace spaces, forming a namespace tree. The root of the tree is known as the global namespace, which is visible to all other spaces in a computer program. This feature is used to organize computer program designs in a modular manner. It is also used to prevent a collision of names: when using two different routine libraries in the same project, it can happen that the same function is declared in both. Without the use of namespace, libraries cannot be used at the same time (in the same module).

The scope of a function or class can be understood as an implicit namespace associated with the visibility, accessibility, and lifespan of member identifiers.

In C++, a namespace is declared through a block. To use one namespace identifier in another, you must specify the prefix of the identifier, that is, the depth path from the global namespace to the namespace the identifier belongs to (separated by ::).