TITLE: scoping with enum types and enumerators (Newsgroups: comp.std.c++, 2 Nov 96) CLAMAGE: clamage@taumet.eng.sun.com (Steve Clamage) >> A using-declaration just brings the specified name into the >> current scope. Bringing the name of the enum type into the current >> scope does not affect the visibility of the enumerators. BIDER: "denis bider" >Why? It seems to me that the opposite would be more practical; just consider >an enum type with a hundred enumerators. HENDERSON: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) As a work-around, you can use the following technique: put each enum in its own nested namespace. Instead of writing namespace bar { ... enum Foo { Foo1, Foo2, ..., Foo100 }; }; write namespace bar { ... namespace foo { enum Foo { Foo1, Foo2, ..., Foo100 }; }; using namespace foo; }; Then, a user of this namespace can write either using bar::Foo; // just imports the enum type name or using namespace bar::foo; // imports both the enum type name // and all the enumerators as they wish. CLAMAGE: It would require a special language rule for using-declarations with the name of an enum type, different from using-declarations for anything else. A special-case language rule ought to solve a serious problem which can't be reasonably dealt with otherwise, and should not introduce new problems. (Unfortunately, I think we already have some special case rules that don't meet this two-part test. That doesn't mean we should add still more.) Now consider this case: namespace N { enum state { off, on }; } namespace M { typedef N::state status; } using N::state; Suppose we say that the using-declaration brings N::off and N::on into the current scope. Now change the last line to this: using M::status; Whether it does or does not bring N::off and N::on into the current scope, it seems to me that we have an inconsistency of some sort. Someone else made a comparison with classes, pointing out that "using" a class name doesn't bring the class members into the current scope. That isn't a valid comparison, since a class creates a new scope, but an enum does not. The enumerators are in the same scope as the enum name. Instead of any of the above, you could put the enum into its own namespace: namespace state { enum state_t { off, on }; } Now a single using-directive using namespace state; makes all the names visible in the current scope.