GregLeck

Untitled

Feb 18th, 2022
633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Object
  6. {
  7. public:
  8.     virtual void BeginPlay();
  9. };
  10.  
  11. class Actor : public Object
  12. {
  13. public:
  14.     virtual void BeginPlay() override;
  15. };
  16.  
  17. class Pawn : public Actor
  18. {
  19. public:
  20.     virtual void BeginPlay() override;
  21. };
  22.  
  23.  
  24. int main()
  25. {
  26.     Object* obj = new Object;
  27.     obj->BeginPlay();
  28.  
  29.     Actor* act = new Actor;
  30.     act->BeginPlay();
  31.  
  32.     Pawn* pwn = new Pawn;
  33.     pwn->BeginPlay();
  34.  
  35.  
  36.     delete obj;
  37.     delete act;
  38.     delete pwn;
  39.     system("pause");
  40. }
  41.  
  42. void Object::BeginPlay()
  43. {
  44.     cout << "Object BeginPlay() called. \n";
  45. }
  46.  
  47. void Actor::BeginPlay()
  48. {
  49.     cout << "Actor BeginPlay() called. \n";
  50.  
  51.     // If we want to call the parent's function:
  52.     Object::BeginPlay();
  53. }
  54.  
  55. void Pawn::BeginPlay()
  56. {
  57.     cout << "Pawn BeginPlay() called. \n";
  58. }
Advertisement
Add Comment
Please, Sign In to add comment