How about:
enum my_type {
a, b, c, d,
last
};
void f() {
my_type test = static_cast<my_type>(rand() % last);
}
More Related Contents:
- Referring to c++ enums [closed]
- c++ Making a code that displays equations and keep getting the “expression must have integral or unscoped enum type” error
- Is there a simple way to convert C++ enum to string?
- How to use enums as flags in C++?
- How can I iterate over an enum?
- How to easily map c++ enums to strings
- Forward declaring an enum in C++
- Base enum class inheritance
- C++ string to enum
- Should I use #define, enum or const?
- Are C++ enums signed or unsigned?
- Enumerate over an enum in C++
- Allow for Range-Based For with enum classes?
- Is it possible to determine if a type is a scoped enumeration type?
- How can I output the value of an enum class in C++11
- What is the underlying type of a c++ enum?
- Extending enums in C++?
- Pros and cons of using nested C++ classes and enumerations?
- Difference between Enum and Define Statements
- How to use C++11 enum class for flags
- How to check if enum value is valid?
- Detect when multiple enum items map to same value
- Why do you use typedef when declaring an enum in C++?
- what is the size of an enum type data in C++?
- Equivalent of “using namespace X” for scoped enumerations?
- namespaces for enum types – best practices
- Do C++ enums Start at 0?
- Why must an enumeration’s size be provided when it is forward declared?
- Signedness of enum in C/C99/C++/C++x/GNU C/GNU C99
- How can I extend a lexical cast to support enumerated types?