Gorchestopher H Gorchestopher H - 1 year ago 84
C++ Question

Is the declaration "const typedef enum" valid in C++?

I thought enums were static, what's the point of a

const enum

For example:

const typedef enum
} Annoying;

I have had an old program dropped on my head that I am being forced to work with (from an equipment manufacturer), and I keep coming across enums being defined with
const typedef enum

Now, I am used to C#, so I don't fully understand all the C++ trickery that goes on, but this case appears to be straightforward.

From the coding of the program it would appear that variables that are of type
are meant to be changed, everywhere, all the time.

They aren't meant to be constant. Long story short, the compiler doesn't like it.

This sample was written back sometime prior to 2010, so this could be some kind of version difference, but what did/does
const typedef enum
even mean?

Answer Source

That makes the type-alias Annoying constant, so all variables declared with that type-aliases are constant:

Annoying a = NORMAL_FUN;
a = GREAT_FUN;  // Failure, trying to change a constant variable
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download