范围解析运算符是否枚举特定于编译器的扩展? [英] Scope resolution operator on enums a compiler-specific extension?
问题描述
您可以使用
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:
在枚举上使用范围解析运算符::(例如在 Colour :: BLUE中)是特定于编译器的扩展,不是标准C ++
Using the scope resolution operator :: on enums (as in "Colour::BLUE") is a compiler-specific extension, not standard C++
是这样吗?我不确定我不确定在MSVC和GCC上都使用过它。
Is that true? I believe I've used that on both MSVC and GCC, though I'm not certain of it.
推荐答案
我尝试了以下代码:
enum test
{
t1, t2, t3
};
void main()
{
test t = test::t1;
}
Visual C ++ 9使用以下警告对其进行编译:
Visual C++ 9 compiled it with the following warning:
警告C4482:使用了非标准扩展名
:在合格的
名称中使用了枚举 test
warning C4482: nonstandard extension used: enum 'test' used in qualified name
看起来好像不是标准的。
Doesn't look like it's standard.
这篇关于范围解析运算符是否枚举特定于编译器的扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!