Enum class EThing : uint8

Hi all

I would like to know what actually operator : does… I have seen :: operators but this looks different…
Can someone explain it?

In this context it specifies the type in which the enum stores it’s data.

It usually denotes inheritance. For example:

class Dog : public Mammal { // Class body }

This creates a class Dog which inherits from a class Mammal.

It kind of makes sense in this context because if you think about it, that specifier uint8 basically means, “Treat these enum values as if they were 8-bit integers.” So in a sense, the enum class is sort of inheriting from uint8. That explanation is not 100% accurate, but no harm will come from looking at it that way for now. I read it as “is a”. (i.e. “Dog is a Mammal”)

When in the context of classes/structs. What about ? : or for (a : b), I think this is the wrong way to explain this.

Implies that you could pass this into a function that takes a uint8, which is one of the things a scoped enum is supposed to prevent.

Not sure you need an analogy or a complicated explanation to explain this.

True, thanks for pointing that out. You cannot really “treat it” like a uint8 but it still “is a” uint8 underneath, which is the point I was trying (and failing) to make. :wink: