-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolymorph.cpp
More file actions
57 lines (36 loc) · 787 Bytes
/
polymorph.cpp
File metadata and controls
57 lines (36 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
class Object {
public:
virtual void BeginPlay();
};
class Actor :public Object {
public:
virtual void BeginPlay() override;
};
class Pawn : public Actor
{
public:
virtual void BeginPlay() override;
};
int main() {
Object* ptr_to_object = new Object;
Actor* ptr_to_actor = new Actor;
Pawn* ptr_to_pawn = new Pawn;
Object* ObjectArray[] = {ptr_to_object, ptr_to_actor, ptr_to_pawn};
for (int i = 0; i < 3; i++)
{
ObjectArray[i]->BeginPlay();
}
delete ptr_to_object;
delete ptr_to_actor;
}
void Object::BeginPlay() {
cout << "Object BeginPlay() called . \n\n";
}
void Actor::BeginPlay() {
cout << "Actor BeginPlay() called . \n\n";
}
void Pawn::BeginPlay() {
cout << "Pawn BeginPlay() called . \n\n";
}