-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes_11_virtual.cpp
47 lines (38 loc) · 925 Bytes
/
notes_11_virtual.cpp
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
#include <iostream>
class Entity
{
public:
virtual std::string GetName() { return "Entity"; }
};
class Player : public Entity
{
public:
// Player(std::string name) : m_name(name) {}
Player(const std::string &name) : m_name(name) {}
std::string GetName() override { return m_name; }
private:
std::string m_name;
};
// This happends because the compiler calls the function
// of the type provided, "Entity";
void callingFunction(Entity *e)
{
std::string name = e->GetName();
std::cout << "The name is : " << name << std::endl;
}
// obsessed with l-value and r-value!!
void testing(const int &name)
{
std::cout << name << std::endl;
}
int main()
{
Entity *e = new Entity();
std::cout << e->GetName() << std::endl;
Player *p = new Player("Aryan");
std::cout << p->GetName() << std::endl;
callingFunction(e);
callingFunction(p);
int a = 1;
testing(a + 1);
}