gpt4 book ai didi

c++ - 枚举特定于编译器的扩展的范围解析运算符?

转载 作者:可可西里 更新时间:2023-11-01 18:08:46 27 4
gpt4 key购买 nike

关于 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com