且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我会收到"错误:预期'}'"在C ++中,但不是在C?

更新时间:2021-08-19 22:50:35

真正是C ++的关键字,所以你不能把它们作为枚举的标识符。

false and true are C++ keywords, so you can't use them as enum identifiers.

在C他们不是关键字,让您的code将工作,但如果包括< stdbool.h> 那么它将无法编译,因为头定义真正为宏。

In C they are not keywords so your code will work, but if you include <stdbool.h> then it will fail to compile because that header defines false and true as macros.

请注意,你可能不应该实现一个布尔类型自己。 C ++已经拥有了布尔类型,如果您使用的是C99编译器,你可以包括 stdbool.h 。这会给你一个布尔类型且具有真正值,类似于C ++。

Note that you probably shouldn't implement a boolean type yourself. C++ already has the bool type, and if you are using a C99 compiler, you can include stdbool.h. This will give you a bool type that has false and true values, similar to C++.