from the below question i sort of get how enums and namespace scoping works
Scope resolution operator on enums a compiler-specific extension?
However with regard to test code below i’m confused as to why in the below code snippet:
1) i can refer to return type in function signature as test_enum::foo_enum
2) however “using namespace test_enum::foo_enum” is not allowed
namespace test_enum {
enum foo_enum {
INVALID,
VALID
};
}
// Case 1) this is allowed
test_enum::foo_enum getvalue() {
return test_enum::INVALID;
}
//Case 2) is not allowed
using namespace test_enum::foo_enum;
is there a particular reason for not allowing case 2 ?
Also are “enums” more of C style construct and better to avoid in C++ code ?
The reason
using namespace test_enum::foo_enum;is not allowed is becausefoo_enumis not a namespace, it is an enum. What works isusing test_enum::foo_enum;I believe what you are trying to do is something like this:
This allows you to throw around
foo_enum_tfreely, but you still have to type outfoo_enum::INVALIDorfoo_enum::VALID