fork download
  1. // In this, the enum is declared globally
  2.  
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. enum Hand {RIGHT,LEFT};
  9.  
  10. class Batsman {
  11. public:
  12. Batsman(string s, Hand h) {
  13. name = s;
  14. hand = h;
  15. }
  16. void setName(string s) {
  17. name = s;
  18. }
  19. void setHand(Hand h) {
  20. hand = h;
  21. }
  22. string getName() {
  23. return name;
  24. }
  25. Hand getHand() {
  26. return hand;
  27. }
  28. private:
  29. string name;
  30. Hand hand;
  31. };
  32.  
  33. int main() {
  34. Batsman B1("Ryder",LEFT);
  35. Batsman B2("McCullum",RIGHT);
  36. }
Success #stdin #stdout 0s 3268KB
stdin
Standard input is empty
stdout
Standard output is empty