Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Accessing the values of an enum defined in a struct
- struct padData
- {
- enum buttonsAndAxes
- {
- select,
- start,
- ps
- };
- };
- padData pad;
- printf ("n%d", pad.buttonsAndAxes[0]);
- error: invalid use of ‘enum padData::buttonsAndAxes’
- printf ("n%d", pad::buttonsAndAxes[0]);
- error: ‘pad’ is not a class or namespace
- printf ("nemit: %d", padData::(select)0);
- error: expected unqualified-id before ‘(’ token
- enum buttonsAndAxes
- {
- select,
- start,
- ps
- };
- const char* buttonsAndAxesNames[] = {
- "select",
- "start",
- "ps"
- };
- printf("%s", buttonsAndAxesNames[select]);
- enum <enum-name> {
- <value-name-0> [= <value-0>],
- <value-name-1> [= <value-1>],
- ...
- };
- enum <enum-name> {
- <value-name-0> [= <value-0>],
- <value-name-1> [= <value-1>],
- ...
- };
- enum Color {
- Blue,
- Green,
- Red
- };
- char const* name(Color c) {
- switch(c) {
- case Blue: return "Blue";
- case Green: return "Green";
- case Red: return "Red";
- }
- assert(0 && "Who stored crap in my enum ?");
- }
Advertisement
Add Comment
Please, Sign In to add comment