Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. __interface IMove {
  7. void Move();
  8. };
  9.  
  10. struct Flying {
  11. virtual void Fly() abstract;
  12. virtual ~Flying() = default;
  13. };
  14.  
  15. class Jumping {
  16. public:
  17. virtual void Jump() abstract;
  18. virtual ~Jumping() = default;
  19. };
  20.  
  21. struct FootMove : IMove {
  22. virtual void Step() abstract;
  23. virtual ~FootMove() = default;
  24. };
  25.  
  26. class Human : FootMove, Jumping, Flying {
  27. protected:
  28. string name;
  29. public:
  30. Human() = delete;
  31. Human(string name) : name(name) {}
  32. virtual ~Human() = default;
  33. };
  34.  
  35. struct Func {
  36. static void MakeMove(IMove* move) {
  37. move->Move();
  38. }
  39.  
  40. };
  41.  
  42. class Lena : Human {
  43. Lena() : Human("Lena") {}
  44. public:
  45. static Lena* Initialize() {
  46. return new Lena();
  47. }
  48. void Move() override {
  49. this->Step();
  50. }
  51. void Jump() override {
  52. cout << "JumP" << endl;
  53. }
  54. void Fly() override {
  55. cout << "I believe, I can fly..." << endl;
  56. }
  57. private:
  58. void Step() override {
  59. cout << "Step!" << endl;
  60. }
  61. };
  62.  
  63. int main(void) {
  64.  
  65. FootMove whynot;
  66. whynot.Step();
  67.  
  68. Lena first;
  69. first.Move();
  70. first.Fly();
  71.  
  72. Lena* second = Lena::Initialize();
  73. second->Move();
  74. second->Fly();
  75. Func::MakeMove((IMove*)(FootMove*)(Human*)second);
  76.  
  77. system("pause > NUL");
  78. return EXIT_SUCCESS;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement