I saw this construct in the project I work:
const enum SomeEnum
{
val0,
val1,
val2
};
What is the purpose of const
here?
I saw this construct in the project I work:
const enum SomeEnum
{
val0,
val1,
val2
};
What is the purpose of const
here?
Nothing at all. Actually, according to G++ it is a compiler error:
error: qualifiers can only be specified for objects and functions
However, in C it is allowed, but useless. GCC says:
warning: useless type qualifier in empty declaration
The issue is that const
only applies to objects (variables) and member functions, but not to basic types.
It doesn't make a difference in your code, but it would in this case:
const enum SomeEnum
{
val0,
val1,
val2
} VAL0 = val0;
Here, VAL0
would be a const
variable (with the value val0
). TBH though, it isn't of much use.