fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. class enumTEST{
  7. enum EMenu {NewGame, PlayAgain, RestartGame, Instructions} emenu;
  8. public:
  9. enumTEST(); // constructor
  10. void testing1(); // test1 member function
  11. void testing2(int a); // test2 member function
  12. void testing3(int a); // test2 member function
  13. };
  14.  
  15. enumTEST::enumTEST(){}; // Nothing to construct?! enum breaks OOP design.
  16. //Shouldn't the deceleration of enum be hidden
  17. //and then constructed like other variables in classes?
  18.  
  19. void enumTEST::testing1(){
  20. //Test Enums, they print fine!
  21. cout<<"Testing 1:\n";
  22. cout<<"NewGame = "<<NewGame<<endl;
  23. cout<<"PlayAgain = "<<PlayAgain<<endl;
  24. cout<<"RestartGame = "<<RestartGame<<endl;
  25. cout<<"Instructions = "<<Instructions<<endl;
  26.  
  27. }
  28.  
  29. void enumTEST::testing2(int choice){
  30. cout<<"\n\nTesting 2:\n";
  31. //Test sending of enum!
  32. switch (choice){
  33. case NewGame:
  34. cout<<"Switch NewGame = "<<NewGame<<endl;
  35. break;
  36. case PlayAgain:
  37. cout<<"Switch PlayAgain = "<<PlayAgain<<endl;
  38. break;
  39. case RestartGame:
  40. cout<<"Switch RestartGame = "<<RestartGame<<endl;
  41. break;
  42. case Instructions:
  43. cout<<"Switch Instructions = "<<Instructions<<endl;
  44. break;
  45. default:
  46. cout<<"Switch default = DEFAULT"<<endl;
  47. break;
  48. };
  49. }
  50.  
  51. void enumTEST::testing3(int choice){
  52. cout<<"\n\nTesting 3:\n";
  53. //Test sending of enum!
  54. switch (choice){
  55. case NewGame:
  56. cout<<"Switch NewGame = "<<NewGame<<endl;
  57. break;
  58. case PlayAgain:
  59. cout<<"Switch PlayAgain = "<<PlayAgain<<endl;
  60. break;
  61. case RestartGame:
  62. cout<<"Switch RestartGame = "<<RestartGame<<endl;
  63. break;
  64. case Instructions:
  65. cout<<"Switch Instructions = "<<Instructions<<endl;
  66. break;
  67. default:
  68. cout<<"Switch default = DEFAULT"<<endl;
  69. break;
  70. };
  71. }
  72.  
  73. int main(){
  74. enumTEST TESTIT;
  75. TESTIT.testing1(); // This works!
  76. TESTIT.testing2(3); // This works!
  77.  
  78. enum EMenu {NGtest, PAtest, RGtest, Itest} emenu;
  79. TESTIT.testing3(Itest);
  80.  
  81. // What I want is to use something like this!
  82. TESTIT.testing2(Instructions); // dosn't work!!
  83.  
  84.  
  85. // Wait until the user presses 'enter' key
  86. cout <<"\n(Main) Press enter to exit...\n";
  87. cin.ignore(10000, '\n');
  88.  
  89. return EXIT_SUCCESS;
  90. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty