The grammar for the C++ namespace constructs is the same as in the coming C++ standard (see section r.3.3.1.1 of [Stroustrup95] and [ANSI95]). (See section 5.2.3.2 Class and Namespace Names for the syntax of namespace-name.) The namespace constructs affect the visibility of names as in C++, and must be implemented by the same constructions in the C++ code.
namespace-definition ::=namespace[ identifier ]{[ declaration-seq ]}|namespaceoriginal-namespace-name{[ declaration-seq ]}declaration-seq ::= [ declaration-seq ] declaration namespace-alias-definition ::=namespaceidentifier=complete-namespace-name;using-declaration ::=usingqualified-id;|usingtypename[::] nested-name-specifier type-name;type-name ::= class-name | non-class-type-name| using-directive ::=usingnamespacecomplete-namespace-name;
See section 9.1 Ghost Variables for the syntax and semantics of spec-decl.
The following are examples of namespace-definitions.
// @(#)$Id: namespace_definition.lh,v 1.9 1998/09/21 20:41:48 leavens Exp $
namespace TerminalUtilities {
enum WhatToDo { flash, freeze, thaw, home, beep };
int x_pos = 0;
int y_pos = 0;
}
//@ uses NoInformation(TerminalControllerClass);
namespace TerminalUtilities { // extension of existing namespace
class TerminalControllerClass {
public:
void TermControl(WhatToDo what) throw();
int num_lines;
// ...
};
typedef TerminalControllerClass TermControl;
namespace AGratuitousNamespace {
int x;
}
}
The following are examples of namespace-alias-definitions.
// @(#)$Id: namespace_alias.lh,v 1.6 1998/09/21 20:41:37 leavens Exp $ #include "namespace_definition.lh" namespace Term = TerminalUtilities; namespace TermAGNamespace = TerminalUtilities::AGratuitousNamespace; namespace TG = Term::AGratuitousNamespace;
The following are examples of using-declarations.
// @(#)$Id: using_declaration.lh,v 1.4 1997/01/04 17:22:02 leavens Exp $ #include "namespace_alias.lh" using Term::x_pos; using ::TerminalUtilities::TerminalControllerClass::num_lines;
The following is an example of a using-directives.
// @(#)$Id: using_directive.lh,v 1.4 1997/01/04 17:22:41 leavens Exp $ #include "namespace_alias.lh" using namespace Term;
Go to the first, previous, next, last section, table of contents.