如何修复 GCC elaborated-type-specifier for a scoped enum must not use the class keyword
问题:
在 C++ 中,你像这样声明 enum class:
enum_class_warning.txt
enum class Shape : uint8_t {
Circle = 0,
Square = 1
};但当你尝试编译项目时,你看到类似这样的错误消息
enum_class_warning_output.txt
include/Shape.hpp:4:6: warning: elaborated-type-specifier for a scoped enum must not use the 'class' keyword
enum class Shape : uint8_t {
~~~~ ^~~~~
-----解决方案
这里的问题是你要从另一个类型派生 enum class - 在此示例中为 uint8_t - 但该类型尚未声明。
所以解决方案是 #include enum class 继承的类型所在的头文件。
在我们的示例中 - 对于类型 uint8_t 和许多其他整型如 int32_t,你可以通过添加
include_cstdint.cpp
#include <cstdint>在 enum class 声明之前。
Check out similar posts by category:
C/C++, GCC Errors
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow