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

标签 c++ standards

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

相关文章:

c++ - 在可移动类型的构造函数 lambda 中安全使用 captured this

c++ - vector 声明 "expected parameter declarator"

c++ - 使用哪种设计模式存储由第一个函数创建的指针,该指针将在以后使用?

c++ - 这个测试是否证明 malloc、calloc、new 在我的系统上管理它们自己的内存池?

c++ - 在 unordered_map Boost 中插入模板值时出错

xml - 为什么 HL7 标准不使用 XML?

JavaScript 事件处理程序执行顺序

api - 为什么 Stripe 使用 Post 方法来更新资源

c++ - 补码架构上的负零行为?

php - 如何在 PHP 中实现 URL 路由