- C++ Game Development By Example
- Siddharth Shekar
- 204字
- 2021-06-24 14:26:13
Enums
Enums are used for enumerating items in a list. When comparing items, it is easier to compare names rather than just numbers. For example, the days in a week are Monday to Sunday. In a program, we will assign Monday to 0, Tuesday to 1, and Sunday to 7, for example. To check whether today is Friday, you will have to count to and arrive at 5. However, wouldn't it be easier to just check if Today == Friday?
For this, we have enumerations, declared as follows:
enum name{ value1, value2, . . . };
So, in our example, it would be something like this:
#include <iostream> #include <conio.h> // Program prints out values to screen enum Weekdays { Monday = 0, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, }; int main() { Weekdays today; today = Friday; if (today == Friday) { std::cout << "The weekend is here !!!!" << std::endl; } _getch(); return 0; }
The output of this is as follows:

Also note, here, Monday = 0. If we don't use initializers, the first item's value is set to 0. Each following item that does not use an initializer will use the value of the preceding item plus 1 for its value.
- 用“芯”探核:龍芯派開發實戰
- Windows phone 7.5 application development with F#
- 龍芯應用開發標準教程
- Camtasia Studio 8:Advanced Editing and Publishing Techniques
- Learning Stencyl 3.x Game Development Beginner's Guide
- scikit-learn:Machine Learning Simplified
- 筆記本電腦維修300問
- Machine Learning with Go Quick Start Guide
- OpenGL Game Development By Example
- Machine Learning Solutions
- Blender Quick Start Guide
- 龍芯自主可信計算及應用
- 基于PROTEUS的電路設計、仿真與制板
- Java Deep Learning Cookbook
- Hands-On Deep Learning for Images with TensorFlow