How to fix GCC elaborated-type-specifier for a scoped enum must not use the 'class' keyword
Problem:
In C++, you are declaring an enum class like this:
enum_class_warning.txt
enum class Shape : uint8_t {
Circle = 0,
Square = 1
};but when you try to compile the project, you see an error message like
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 {
~~~~ ^~~~~
-----Solution
The issue here is that you are deriving the enum class from another type - uint8_t in this example - but that type has not been declared.
So the solution is to #include the header where the type from which the enum class is inherited.
In our example - for the type uint8_t and for many other integral types such as int32_t , you can do that by adding
include_cstdint.cpp
#include <cstdint>before the enum class declaration.
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