\begin{DoxyParagraph}{Description}
Namespaces allow \mbox{\hyperlink{constants}{constants}}, \mbox{\hyperlink{qore_classes}{classes}}, \mbox{\hyperlink{qore_functions}{functions}}, \mbox{\hyperlink{variables_our}{global variables}}, and even other namespaces to co-\/exist in the same program by defining them in separate namespaces. Constants, classes, functions, 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, function, or namespace declaration separated by two colons {\ttfamily \char`\"{}\+::\char`\"{}}. Global variables can only be declared out of line so they can be initialized when they are declared.~\newline
~\newline
 If the user does not specify the parent namespace with a namespace path in constant, class, function, global variable, or namespace declarations, the declaration will be by default in the unnamed default root namespace.
\end{DoxyParagraph}
\label{qore_namespaces_namespace_declarations}%
\Hypertarget{qore_namespaces_namespace_declarations}%
 \begin{DoxyParagraph}{In-\/\+Line Namespace Declaration}
{\ttfamily \mbox{[}\mbox{\hyperlink{qore_modules_mod_public}{public}}\mbox{]} {\bfseries{namespace}}} {\itshape \mbox{[}namespace\+\_\+path\+:\+:\mbox{]}namespace\+\_\+identifier} {\ttfamily \{}~\newline
 ~~~~{\itshape \mbox{[}\mbox{\hyperlink{constants}{constant\+\_\+declarations}}\mbox{]}}~\newline
 ~~~~{\itshape \mbox{[}\mbox{\hyperlink{qore_classes}{class\+\_\+declarations}}\mbox{]}}~\newline
 ~~~~{\itshape \mbox{[}\mbox{\hyperlink{qore_functions}{function\+\_\+declarations}}\mbox{]}}~\newline
 ~~~~{\itshape \mbox{[}\mbox{\hyperlink{variables_global_variables}{global\+\_\+variable\+\_\+declarations}}\mbox{]}}~\newline
 ~~~~{\itshape \mbox{[}namespace\+\_\+declarations\mbox{]}}~\newline
 {\ttfamily \}}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Out of Line Namespace Declaration}
{\ttfamily \mbox{[}\mbox{\hyperlink{qore_modules_mod_public}{public}}\mbox{]} {\bfseries{namespace}}} {\itshape namespace\+\_\+identifier}{\ttfamily ;}
\end{DoxyParagraph}
\begin{DoxyNote}{Note}
No namespace path may be given with out of line namespace declarations.
\end{DoxyNote}
When defining a \mbox{\hyperlink{qore_modules_user_modules}{user module}}, namespace declarations can be preceded by \mbox{\hyperlink{qore_modules_mod_public}{public}}, which means that the namespace\textquotesingle{}s public contents will be exported into the \mbox{\hyperlink{class_qore_1_1_program}{Program}} object importing the module. When a namespace is declared \mbox{\hyperlink{qore_modules_mod_public}{public}} outside of a \mbox{\hyperlink{qore_modules_user_modules}{user module}}, it means that the namespace can be inherited in any child \mbox{\hyperlink{class_qore_1_1_program}{Program}} objects created in the same scope. See \mbox{\hyperlink{qore_modules_mod_public}{public}} for more information.

\label{qore_namespaces_namespace_resolution}%
\Hypertarget{qore_namespaces_namespace_resolution}%
 \begin{DoxyParagraph}{Namespace Resolution}
Namespaces can either be resolved by giving a path to the constant, class, function, global variable, or namespace desired, or by leaving out the namespace path and allowing the system to search for the constant, class, function, global variable, or namespace. In either case, a depth-\/first search of the namespace tree is made for a match.~\newline
~\newline
 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.
\end{DoxyParagraph}
\label{qore_namespaces_namespace_paths}%
\Hypertarget{qore_namespaces_namespace_paths}%
 \begin{DoxyParagraph}{Namespace Paths}
Namespace paths look like the following\+:~\newline

\begin{DoxyItemize}
\item {\itshape starting\+\_\+namespace\+:\+:\mbox{[}sub\+\_\+namespace(s)s\+:\+:\mbox{]}constant$\vert$class$\vert$namespace}
\end{DoxyItemize}
\end{DoxyParagraph}
\begin{DoxyParagraph}{Example}

\begin{DoxyCode}{0}
\DoxyCodeLine{namespace MyNamespace \{}
\DoxyCodeLine{    \textcolor{comment}{\# global variable declarations in a namespace declaration cannot be initialized at the point they are declared}}
\DoxyCodeLine{    our bool my\_bool;}
\DoxyCodeLine{}
\DoxyCodeLine{    const MyConst = 1;}
\DoxyCodeLine{    \textcolor{keyword}{class }MyClass \{}
\DoxyCodeLine{    \}}
\DoxyCodeLine{    namespace MySubNamespace;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{comment}{\# out of line initialization for MyNamespace::my\_bool}}
\DoxyCodeLine{MyNamespace::my\_bool = \textcolor{keyword}{False};}
\DoxyCodeLine{\textcolor{comment}{\# out of line declaration and initialization for MyNamespace::my\_int}}
\DoxyCodeLine{our int MyNamespace::my\_int = 200;}
\end{DoxyCode}

\end{DoxyParagraph}
\begin{DoxyNote}{Note}
No semicolon ({\ttfamily \char`\"{};\char`\"{}}) should follow the closing bracket in a namespace declaration (in fact using a semicolon in this case would raise a parse exception). 
\end{DoxyNote}
