Guest User

Untitled

a guest
May 18th, 2012
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. Accessing the values of an enum defined in a struct
  2. struct padData
  3. {
  4. enum buttonsAndAxes
  5. {
  6. select,
  7. start,
  8. ps
  9. };
  10. };
  11.  
  12. padData pad;
  13.  
  14. printf ("n%d", pad.buttonsAndAxes[0]);
  15.  
  16. error: invalid use of ‘enum padData::buttonsAndAxes’
  17.  
  18. printf ("n%d", pad::buttonsAndAxes[0]);
  19.  
  20. error: ‘pad’ is not a class or namespace
  21.  
  22. printf ("nemit: %d", padData::(select)0);
  23.  
  24. error: expected unqualified-id before ‘(’ token
  25.  
  26. enum buttonsAndAxes
  27. {
  28. select,
  29. start,
  30. ps
  31. };
  32.  
  33. const char* buttonsAndAxesNames[] = {
  34. "select",
  35. "start",
  36. "ps"
  37. };
  38.  
  39. printf("%s", buttonsAndAxesNames[select]);
  40.  
  41. enum <enum-name> {
  42. <value-name-0> [= <value-0>],
  43. <value-name-1> [= <value-1>],
  44. ...
  45. };
  46.  
  47. enum <enum-name> {
  48. <value-name-0> [= <value-0>],
  49. <value-name-1> [= <value-1>],
  50. ...
  51. };
  52.  
  53. enum Color {
  54. Blue,
  55. Green,
  56. Red
  57. };
  58.  
  59. char const* name(Color c) {
  60. switch(c) {
  61. case Blue: return "Blue";
  62. case Green: return "Green";
  63. case Red: return "Red";
  64. }
  65. assert(0 && "Who stored crap in my enum ?");
  66. }
Advertisement
Add Comment
Please, Sign In to add comment