I made an enum as:
enum class KeyPressSurfaces {
KEY_PRESS_SURFACE_DEFAULT,
KEY_PRESS_SURFACE_UP,
KEY_PRESS_SURFACE_DOWN,
KEY_PRESS_SURFACE_LEFT,
KEY_PRESS_SURFACE_RIGHT,
KEY_PRESS_SURFACE_TOTAL
};
and later on I attempt to define an array as I typed below, but I received the error, size of array 'KEY_PRESS_SURFACES' has non-integral type 'KeyPressSurfaces'
SDL_Surface*KEY_PRESS_SURFACES[KeyPressSurfaces::KEY_PRESS_SURFACE_TOTAL];
I understand the error fine, but I don't know where to move the KeyPressSurfaces to qualify the constant in the enum.
I also realize I could just use an enum and not an enum class, but I feel like this should work, and I want to learn how to do this.
Any response/advice?
KEY_PRESS_SURFACE_TOTALautomatically adjust. It's a good technique actually to use enum for the array size. When it's a constant number, you have to edit all part in the codes that are related to the size of that array specially on some computation where the size-of-the-array is involve.enum classes are scoped, I would've thought half of the point of them is to avoid you having to repeat ugly prefixes likeKEY_PRESS_SURFACE_on every enumerator. You don't need to protect the global namespace anymore. By thinking you do, now you have to write it twice...KeyPressSurfaces::KEY_PRESS_SURFACE_DEFAULTYuk! Just drop the prefix, drop theALL_CAPStoo because there are no macros here, drop the plural that IMO is unnecessary and best reserved for instances of collections, and writeKeyPressSurface::default. Much better.KeyPressSurface::defaultwhich will simply not compile. Using Google guidelines you would instead write something likeKeyPressSurface::kDefault(google.github.io/styleguide/cppguide.html#Enumerator_Names)