On this question, there's an answer that states:
You can use typedef to make Colour enumeration type accessible without specifying it's "full name".
typedef Sample::Colour Colour; Colour c = Colour::BLUE;
That sounds correct to me, but someone down-voted it and left this comment:
Using the scope resolution operator :: on enums (as in "Colour::BLUE") is a compiler-specific extension, not standard C++
Is that true? I believe I've used that on both MSVC and GCC, though I'm not certain of it.
I tried the following code:
enum test
{
t1, t2, t3
};
void main()
{
test t = test::t1;
}
Visual C++ 9 compiled it with the following warning:
warning C4482: nonstandard extension used: enum 'test' used in qualified name
Doesn't look like it's standard.
That is not standard.
In C++11, you will be able to make scoped enums with an enum class declaration.
With pre-C++11 compilers, to scope an enum, you will need to define the enum inside a struct or namespace.
This is not allowed in C++98. However, staring from C++11 you can optionally use scope resolution operator with "old-style" enums
enum E { A };
int main()
{
A; // OK
E::A; // Also OK
}
Both ways of referring to A
are correct in C++11 and later.
In standard c++, things to the left of "::" must be a class or namespace, enums don't count.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With