You can't.
A pointer of type Person
can only be used to access data/addresses(functions) that are part of the Person
object. The compiler simply has no way of knowing what all classes could be deriving from Person
and hence which operations are legal.
Have a look at Dynamic casting. MSDN Reference | Tutorial
In brief:
Player* pPlayer = dynamic_cast<Player*>(pPerson);
if (pPlayer) {
//Use the pointer like a player pointer
//Note: You can only call player functions from pPlayer, not pPerson
} else {
//Use the pointer like a person pointer
}
Note that this casting is a runtime operation. At compile time, the compiler sees you using the Player
pointer to access Player
code, which it is happy to allow!
Disclaimer: I found your code tough to follow, so consider this an answer to your question in text