Topic: hierarchical namespaces
Author: rad2r@uvacs.cs.Virginia.EDU (Robert DeLine)
Date: Sat, 16 Jan 1993 20:14:24 GMT Raw View
Before starting further discussion, is the following C++
construction legal?
struct ClassLibrary {
class Class1;
class Class2;
};
class ClassLibrary::Class1 {
// flesh out Class1
};
class ClassLibrary::Class2 {
// flesh out Class2
};
GCC 2.2.2 accepts it, but that doesn't count for much. (Sorry,
but I don't own the ARM, or I'd look it up myself.)
If it *is* legal, then what are opinions on using this to create
hierarchical namespaces?
Many programmers, in order to prevent name clashes (e.g. everyone
using names like Boolean, TRUE, Stack, etc.), use prefixes like
this: RD_Boolean, RD_TRUE, RD_Stack. However, if the construct
above is legal, then a programmer can just nest the classes inside
one struct and use the :: operator instead. This outermost struct
is not unlike a "module" or a "package" in other languages. Note
too that this nesting could be arbitrarily deep, for example
HugeLibrary::UserInterface::Geometry::Rectangle. Annoying
if overdone, perhaps, but possible.
As far as packaging goes, each class could still have a separate
header file, but that header file would include a common header
file that contained the definition of the outermost struct.
Thoughts on this?
Rob DeLine
Computer Science, University of Virginia
deline@Virginia.EDU