This question is driving me crazy. I need to get it right so I can pass my class. Thank you to all that try it.
Write a simple program in C++ to investigate the safety of its enumeration types. Include at least 10 different operations on enumeration types to determine what incorrect or just silly things are legal.
Here is a fully operational program that shows ten different types of operations with enums. Details will be in the code, references will be at the bottom of the post.
First, it is very important you understand what enums are. For a reference on this, take a look at Enumerated Types – enums. In the code below I use mathematical operations, bitwise operators and use an enum value to initialize an array to a default size.
The code sample done above can be done in another way, which is where you overload the operator|, etc for EnumBits. This is a commonly used technique, for additional references please see How to use enums as flags in C++?.
For a reference on bitwise operations, take a look at Bitwise Operators in C and C++: A Tutorial
Using C++ 11 you can use enums in additional ways, such as strongly typed enums.