C++11—Specifying the Type of an enum’s Constants

Image

The constants in an enum are represented as integers. By default, an unscoped enum’s underlying integral type depends on its constants’ values—the type is guaranteed to be large enough to store the constant values specified. By default, a scoped enum’s underlying integral type is int. C++11 allows you to specify an enum’s underlying integral type by following the enum’s type name with a colon (:) and the integral type. For example, we can specify that the constants in the enum class Status should have type unsigned int, as in

enum class Status : unsigned int { CONTINUE, WON, LOST };


Image Common Programming Error 6.6

A compilation error occurs if an enum constant’s value is outside the range that can be represented by the enum’s underlying type.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.196.175