1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
Namespaces are defined according to the following syntax:
verb( namespace identifier
{
// declared or defined entities
// (declarative region)
})
The identifier used when defining a namespace is a standard bf(C++)
identifier.
Within the emi(declarative region), introduced in the above code example,
functions, variables, structs, classes and even (nested) namespaces can be
defined or declared. Namespaces cannot be defined within a function
body. However, it is possible to define a namespace using multiple
em(namespace) declarations. Namespaces are `em(open)' meaning that
a namespace tt(CppAnnotations) could be defined in a file tt(file1.cc) and
also in a file tt(file2.cc). Entities defined in the tt(CppAnnotations)
namespace of files tt(file1.cc) and tt(file2.cc) are then united in one
tt(CppAnnotations) namespace region. For example:
verb( // in file1.cc
namespace CppAnnotations
{
double cos(double argInDegrees)
{
...
}
}
// in file2.cc
namespace CppAnnotations
{
double sin(double argInDegrees)
{
...
}
})
Both tt(sin) and tt(cos) are now defined in the same
tt(CppAnnotations) namespace.
Namespace entities can be defined outside of their namespaces. This
topic is discussed in section ref(OUTSIDE).
|