I've been taking CodingMadeEasy's C++ Made Easy HD tutorials (If you'r not familiar with him, he's a youtuber that gives amazing lessons in multiple programming languages and libraries), and lately I've been taking his lesson on Polymorphism as he's teaching us object oriented programming. I've been understanding all the stuff he's been teaching us, but I've gotten rather stuck where he decides to call a method from the "Player" class without an instance of the class. Only one line of code bugs me and in turn causes me to misunderstand the rest of the example. The line of code is:
class Entity
{
protected:
int atkPow;
public:
void SetAtkPower(int value)
{
atkPow = value;
}
};
class Player : public Entity
{
public:
void Attack()
{
cout << "Player Attack: " << atkPow << endl;
}
};
int main()
{
Entity *entity = new Player; //THIS IS THE LINE OF CODE THAT I CAN'T UNDERSTAND
entity->SetAtkPower(10);
delete entity;
}
Now as far as I'm concerned, I should understand all dynamic memory has to offer, but how is an instance of the Entity class pointing to new Player?
Here is the CodingMadeEasy tutorial. The bit in which I fail to understand start 8 minutes in.
If somebody could clarify things for me, I'd greatly appreciate it. Thank you in advance :)