scoped enumerations

i would like to use scoped enumeration in my project.
declaring an unscoped enum as a public member of a class works as intended:

enum deviceType_t_ { GENERAL, CAMERAROTATOR, DOME, FILTERWHEEL, FOCUSER, SAFETYMONITOR, TELESCOPE };

but scoped declaration of the same enum enum class deviceType_t_ { GENERAL, CAMERAROTATOR, DOME, FILTERWHEEL, FOCUSER, SAFETYMONITOR, TELESCOPE };gives me the following error:

EEPROMHandler.h:15: error: expected identifier before 'class'
EEPROMHandler.h:15: error: ISO C++ forbids declaration of 'GENERAL' with no type
EEPROMHandler.h:15: error: ISO C++ forbids declaration of 'CAMERAROTATOR' with no type
EEPROMHandler.h:15: error: ISO C++ forbids declaration of 'DOME' with no type
EEPROMHandler.h:15: error: ISO C++ forbids declaration of 'FILTERWHEEL' with no type
EEPROMHandler.h:15: error: ISO C++ forbids declaration of 'FOCUSER' with no type
EEPROMHandler.h:15: error: ISO C++ forbids declaration of 'SAFETYMONITOR' with no type
EEPROMHandler.h:15: error: ISO C++ forbids declaration of 'TELESCOPE' with no type
EEPROMHandler.h:15: error: expected ';' before '}' token
EEPROMHandler.h:15: error: expected `;' before '}' token
EEPROMHandler.h:15: error: multiple types in one declaration

any ideas? what i want to do in my code is to compare an uint8_t to enumerators of a specific enum.

you need to wrap your enums within a class object; you cannot define an enum as a class yet :slight_smile: the link you gave with scoped enumerations is specific to C++11 which isn't supported by the compilers provided with the Arduino IDE.

is how you could do it now - that way you could have the same enumeration constant names within an object definition and reference them as myObject::ENUM_VALUE. thats the best you can probably do now.

wrapping the enums in a struct like struct device_type_ { enum deviceType_t_ { GENERAL, CAMERAROTATOR, DOME, FILTERWHEEL, FOCUSER, SAFETYMONITOR, TELESCOPE }; }; does exactly what i want. thanks for the tip :slight_smile: