C++11- enum class with underlying type

C++11 allows us to specify the underlying type for enum class as shown below. If specified value is not in the range of the underlying type, compiler can catch error as well.

enum class Color : unsigned char
    Red = 0x01,
    Green = 0x02,
    Blue = 0x04

Getting underlying type from enum type

std::underlying_type<Color>::type value;
This entry was posted in C++, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s