未申报的枚举?

在编译此代码时:

#include  enum Boolean { TRUE, FALSE }; int main(int argc, char **argv) { printf("%d", Boolean.TRUE); return 0; } 

我越来越:

错误:’布尔’未声明(首次在此函数中使用)

我做错了什么?

在C中,您不使用语法EnumType.SpecificEnum访问单独的枚举常量。 你只想说SpecificEnum 。 例如:

 printf("%d", TRUE); 

当你写作

 printf("%d", Boolean.TRUE); 

C认为您正在尝试转到名为Booleanstructunion并访问TRUE字段,因此编译错误。

希望这可以帮助!

只需写入TRUE而不使用布尔值。

 #include  enum Boolean { FALSE, TRUE }; struct { const enum Boolean TRUE; const enum Boolean FALSE; } Boolean = { TRUE, FALSE }; int main(){ printf("%d\n", Boolean.TRUE); return 0; } 

你写了Boolean. 只要在没有该前缀的情况下写入TRUEFALSE