gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:41:49 27 4
gpt4 key购买 nike

给定程序:

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/

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