指定枚举基础类型时的"ISO C++ forbids forward references to 'enum' types"
"ISO C++ forbids forward references to 'enum' types" when specifying enum underlying type
给定程序:
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或无符号int中,否则底层整型是由实现定义的。(但是,自VS 2005以来,Microsoft的编译器允许将枚举的底层类型指定为专有扩展。(
相关文章:
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- 完美前进使用 std::forward vs RefRefCast
- 构建 TensorFlow r1.14 C++文件时缺少文件"tensorflow/core/framework/types.pb.h"
- 你如何理解"std: :forward is just syntactic sugar"?这是真的吗?
- "std::forward"和"std::move"真的不生成代码吗?
- 在C++中使用 std::forward 的多个参数
- 如何使用 std::forward 精确地评估参数包的扩展?
- 为什么"types may not be defined in parameter types"
- 如何在Arduino程序中解决"invalid operands of types"?
- 普通的右值引用和 std::forward 返回的引用有什么区别?
- 怎么可能写 f( *this, std::forward<Args>(args)... ) 而 f 只用 F f 声明;
- 如何通过通用引用或std::forward将这三个c++模板函数合并为一个
- C++模块(MSVC)中的visual Forward声明
- 错误"invalid types ... for array subscript"是什么意思?
- 自 C++11 年以来对 std::forward 实施的理解
- 当将参数包传递给另一个可变参数模板函数时,我是否必须使用 std::forward
- 为什么要在概念中使用std::forward
- 寻求对std::forward的澄清
- 无法打开源文件"sys/types.h"、"sys/stat.h"
- 指定枚举基础类型时的"ISO C++ forbids forward references to 'enum' types"