How to use enum in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use enum in c++

I'm a bit conversant with enum in c but not in c++ are they the same or is there any addition or replacement

25th Dec 2016, 3:06 PM
Tam Chidi Obi
Tam Chidi Obi - avatar
1 Answer
+ 1
There are some small chages, but C enums also works in C++ 1)In C++ enum can be declared as enum class Color{Red, Green, Blue} and only one way is allowed to access e.g.: Color color = Color::Red; ... if(color == Color.Green){} also you can using forward declaration enum class Color; 2)You can change the size: enum class Color : char {...} so sizeof(Color) == sizeof(char)
25th Dec 2016, 3:19 PM
Vladislav
Vladislav - avatar