Re: C++11: Replacing unscoped enums with scoped enums



2015-08-13 10:56 GMT+02:00 Murray Cumming <murrayc murrayc com>:
C++11 lets us use this:

enum class SomeEnum
{
  VALUE_A,
  VALUE_B
}

instead of the old way:

enum SomeEnum
{
  SOME_ENUM_VALUE_A,
  SOME_ENUM_VALUE_B
}

So, you'd then use SomeEnum::VALUE_A instead of SOME_ENUM_VALUE_A.

That's nicer, avoids some namespace pollution, and also lets us declare
the type without defining it.

However, I guess we can't just replace enum with "enum class" without
breaking ABI, right? I don't mind so much about breaking API.

It depends on the name mangling scheme. If enums are mangled into the
function names in the same way as enum classes, then this could work.

There's also the issue of the size of underlying type: in C++11, the
underlying type is always int, but in C++03 the standard allows it to
be short or even char. GCC will generate such code If one uses
-fshort-enums, but as far as I can tell, the default is to always use
int.

Regards, Krzysztof


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]