There are two reasons why your approaches fail:
The first reason has been described by BЈовић: You cannot introduce the name of a nested type in a namespace scope, see [namespace.udecl]/8.
When you write
using A::B::Value;
, only the name of theenum
itself will be introduced in the current scope, not the name of all enumerators. This allows things like:namespace Values { enum Value{ VALUE1, VALUE2 }; } using Values::Value; // don't pollute my scope with the enumerators Value v = Values::VALUE1;
The second issue can be solved by introducing the enumerators individually:
namespace A
{
namespace B
{
enum Value
{
VALUE1
, VALUE2
};
}
}
int main()
{
using A::B::Value;
using A::B::VALUE1;
using A::B::VALUE2;
Value v = VALUE1;
v = VALUE2;
}
Alternatively, as hvd suggested in a comment, you can use a using-directive to introduce all names of a namespace:
namespace A
{
namespace B
{
enum Value
{
VALUE1
, VALUE2
};
}
}
int main()
{
using namespace A::B;
Value v = VALUE1;
v = VALUE2;
}