关于 this question , 有 an answer指出:
You can use typedef to make Colour enumeration type accessible without specifying it's "full name".
typedef Sample::Colour Colour; Colour c = Colour::BLUE;
这对我来说听起来是对的,但有人投了反对票并留下了这条评论:
Using the scope resolution operator :: on enums (as in "Colour::BLUE") is a compiler-specific extension, not standard C++
这是真的吗?我相信我在 MSVC 和 GCC 上都使用过它,尽管我不确定。
最佳答案
我尝试了以下代码:
enum test
{
t1, t2, t3
};
void main()
{
test t = test::t1;
}
Visual C++ 9 编译时出现以下警告:
warning C4482: nonstandard extension used: enum 'test' used in qualified name
看起来不像是标准的。
关于c++ - 枚举特定于编译器的扩展的范围解析运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/441552/