c++ - "ISO C++ forbids forward references to ' 枚举 ' types"指定枚举基础类型时

标签 c++ clang

给定程序:

enum E : int
{
    A, B, C
};

g++ -c test.cpp 工作得很好。但是,clang++ -c test.cpp 给出以下错误:

test.cpp:1:6: error: ISO C++ forbids forward references to 'enum' types
enum E : int
     ^
test.cpp:1:8: error: expected unqualified-id
enum E : int
       ^
2 errors generated.

这些错误消息对我来说没有任何意义。我在这里看不到任何前向引用。

最佳答案

为枚举指定基础类型是 C++11 语言功能。要编译代码,您必须添加开关 -std=c++11。这适用于 GCC 和 Clang。

对于 C++03 中的枚举,底层整数类型是实现定义的,除非枚举数的值不能适合 int 或 unsigned int。 (但是,自 VS 2005 起,Microsoft 的编译器允许将枚举的底层类型指定为专有扩展。)

关于c++ - "ISO C++ forbids forward references to ' 枚举 ' types"指定枚举基础类型时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38777701/

相关文章:

c++ - GCC编译器错误: -Werror=stringop-truncation: no option

C++ 重载 [] 使用模板访问子 vector

plugins - 如何注册 clang 预处理器插件?

c++ - 为什么clang不能启用所有的 sanitizer ?

c++ - Clang 不导出 C++ 符号

c++ - 在 NetBeans 中集成 Clang?

c++ - 链接失败,并带有对libboost_thread的 undefined reference

c++ - 函数原型(prototype)与 C++ 类中的任何原型(prototype)都不匹配

c++ - 在大型 C++ 项目中搜索基类的整个派生类列表

c++ - 没有将 bool 隐式转换为浮点类型的警告?