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:

example.txt
enum class Shape : uint8_t {
    Circle = 0,
    Square = 1
};

but when you try to compile the project, you see an error message like

example.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

example.cpp
#include <cstdint>

before the enum class declaration.


Check out similar posts by category: C/C++, GCC Errors