2.17. Namespaces

Namespaces allow constants, classes, and even other namespaces with the same name to co-exist in the same program by defining them in separate namespaces. Constants, classes, and sub-namespaces can be declared to belong to a particular namespace either by defining them in-line within a namespace declaration, or by including the namespace name/path prepended to the constant, class, or namespace declaration separated by two colons "::".

If the user does not specify the parent namespace with a namespace path in constant, class, or namespace declarations, the declaration will be by default in the unnamed default root namespace.

2.17.1. Namespace Declarations

In-line namespace declaration:

namespace [namespace_path::]namespace_identifier {
    [constant_declarations]
    [class_declarations]
    [sub-namespace-declarations]
}

Out of line namespace declaration:

namespace [namespace_path::]namespace_identifier;

2.17.2. Namespace Resolution

Namespaces can either be resolved by giving a path to the constant, class, or namespace desired, or by leaving out the namespace path and allowing the system to search for the constant, class, or namespace. In either case, a breadth-first search of the namespace tree is made for a match. If a namespace path is included, then the tree is searched for the first namespace match. and, if the rest of the declaration cannot be matched, the search continues in the entire namespace tree until a complete match is found.

Namespace paths look like the following:

starting_namespace::[sub-namespaces::]constant|class|namespace

2.17.3. System Namespaces

All Qore-language constants and classes are defined in the Qore namespace or in a subnamespace of the Qore namespace. The Qore namespace is a direct child of the unnamed default root namespace (::).

For detailed information on all constants and classes defined in system namespaces, see System Namespaces and Class Library.