#include
enum ExprValueType : uint8_t {
MinInf = 1
};
int main(int argc, char* argv[]) {
ExprValueType type = MinInf;
std::cout
使用 g++ abc.cc -o a.out -std=c++20 报错,报错信息如下所示
abc.cc:3:20: error: found ‘:’ in nested-name-specifier, expected ‘::’
3 | enum ExprValueType : uint8_t {
| ^
| ::
abc.cc:3:6: error: ‘ExprValueType’ has not been declared
3 | enum ExprValueType : uint8_t {
| ^~~~~~~~~~~~~
abc.cc:3:30: error: expected unqualified-id before ‘{’ token
3 | enum ExprValueType : uint8_t {
| ^
abc.cc: In function ‘int main(int, char**)’:
abc.cc:8:3: error: ‘ExprValueType’ was not declared in this scope
8 | ExprValueType type = MinInf;
| ^~~~~~~~~~~~~
abc.cc:10:16: error: ‘type’ was not declared in this scope; did you mean ‘std::__cmp_cat::type’?
10 | std::cout
个人猜测是 gcc 版本的问题,于是在 https://gcc.godbolt.org/ 切换不同的编译器查看。
于是产生了两个困惑
添加头文件 #include 后就正常了。
但是为什么之前版本的 gcc 就不需要添加这个头文件呢?