Skip to content

Instantly share code, notes, and snippets.

@kkabdol
Last active February 12, 2016 17:01
Show Gist options
  • Save kkabdol/5fce58a289d300e373a2 to your computer and use it in GitHub Desktop.
Save kkabdol/5fce58a289d300e373a2 to your computer and use it in GitHub Desktop.
strongly typed enumerations
enum Animals { Bear, Cat, Chicken };
//enum Birds { Eagle, Duck, Chicken }; // error!
enum class Fruits { Apple, Pear, Orange };
enum class Colours { Blue, White, Orange }; // no problem!
Colours r = Colours::Orange;
// int n = r; // error !
int n = static_cast<int>(r); // OK, n = 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment