16.2.5 Namespaces

back: variable scoping in for loops
forward: the explicit keyword
 
fastback: the explicit keyword
up: changeable c++
fastforward: compiler quirks
top: autoconf, automake, and libtool
contents: table of contents
index: index
about: about this document

C++ namespaces are a facility for expressing a relationship between a set of related declarations such as a set of constants. Namespaces also assist in constraining names so that they will not collide with other idential names in a program. Namespaces were introduced to the language in 1993 and some early compilers were known to have incorrectly implemented namespaces. Here's a small example of namespace usage:

 
 namespace Animals {   class Bird {   public:     fly (); {} // fly, my fine feathered friend!   }; }; // Instantiate a bird. Animals::Bird b; 

For compilers which do not correctly support namespaces it is possible to achieve a similar effect by placing related declarations into an enveloping structure. Note that this utilises the fact that C++ structure members have public protection by default:

 
 struct Animals {   class Bird {   public:     fly (); {} // fly, my find feathered friend!   }; protected   // Prohibit construction.   Animals (); }; // Instantiate a bird. Animals::Bird b; 

This document was generated by Gary V. Vaughan on May, 24 2001 using texi2html


GNU Autoconf, Automake and Libtool
GNU Autoconf, Automake, and Libtool
ISBN: 1578701902
EAN: 2147483647
Year: 2002
Pages: 290

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net