Do you 'enum EList' or 'enum class EList : uint8'

I usually just go with enum but then sometimes I’m annoyed when I declare a new variable and have to write TEnumAsByte<enum EList> var;

Is there any difference after the initial declaration of the enum and variables?

What do you do and why?

Dear Burnrate,

The uint8 extending enum as a strongly-typed “enum class” is the new C++ 11 standard and I can highly recommend it!

enum class EJoyButtonActions : uint8
	None			UMETA(DisplayName="None"),
	Appear			UMETA(DisplayName="Appear"),
	Disappear		UMETA(DisplayName="Disappear"),
	Activate		UMETA(DisplayName="Activate Now!")

I use it because it because it allows me to easily cast to uint8 if I need to, and because it is frankly easier to look at / more compact than the older format :slight_smile:

The UMETA stuff is optional, and is the way it appears in BP, which I tried to make more obvious with “Activate”.



1 Like

As the infamous Nick Darnell once said:

So yeah, use class-based enums. Things like >= <= etc become valid with uint8 too.

Like the others already said, enum class is way better. By the way, here is a neat trick I only recently found out to easily use enum classes as bitmasks:

enum class ESpeakerPosition : uint32
	Undefined = 0x00,
	FrontLeft = 0x01,
	FrontRight = 0x02,
	FrontCenter = 0x04,
	LowFrequency = 0x08,
	BackLeft = 0x10,
	BackRight = 0x20,


Now you can do

ESpeakerPosition Stereo = ESpeakerPosition::FrontLeft | ESpeakerPosition::FrontRight;

If you want UENUM()s that are usable as bitmasks in blueprints and the editor, check out the changelog for 4.12! The example they show uses a regular enum; I haven’t tried it yet so I don’t know if it works with enum classses. One thing you should keep in mind when making enum classes a UPROPERTY() is that the underlying type must be uint8.

Thanks all! I should be better versed in the standards :eek:

I didn’t know that you could use other that the uint8 when not using it as a BlueprintType either.