The new C++ (C++0x or C++11) has an new kind of enum, an “enum class” where the names are scoped to the enum (among other things).
enum class E {
VAL1, VAL2
};
void fun() {
E e = E::VAL1; // Qualified name
}
I’m wondering, however, if I can selectively use the unqualified name in a certain scope. Something like:
void fun() {
using E::*;
E e = VAL1;
switch (e) {
case VAL2: ...
I see I can write using E::VAL1 and get one value. But I don’t want to do that for every value of a larger enum.
There is no way to do this in C++11. Just in case you are not aware of it – you get the
E::Val1notation even for an unscoped enumeration. For such an enumeration, you haveVal1accessible with and without the use ofE::.But you cannot take a scoped enumeration and selectively make all its enumerators visible in a given scope. It should also be noted that you can not write
using E::Val1. The spec explicitly forbids this, your compiler just doesn’t reject it yet.