That is because it is unscoped enumerator and so each enumerator is available in the same scope as the enum name itself. A scoped enumerator would require to use of ::
. This is covered in the C++ draft standard section 7.2
Enumeration declarations paragraph 10 which says:
Each enum-name and each unscoped enumerator is declared in the scope that immediately contains the enum-specifier. Each scoped enumerator is declared in the scope of the enumeration. These names obey the scope rules defined for all names in (3.3) and (3.4).
and provides the following example, the first example with direction
uses an unscoped enumerator and does not require the use of ::
but the second example with altitude
is scoped and thus requires the use of ::
:
enum direction { left=’l’, right=’r’ };
void g() {
direction d; // OK
d = left; // OK
d = direction::right; // OK
}
enum class altitude { high=’h’, low=’l’ };
void h() {
altitude a; // OK
a = high; // error: high not in scope
a = altitude::low; // OK
}