I have an array of objects whose class is a base class, and the elements of the array are derived classes.
Object *object [kNumPlayers] =
{
new Human ("Ms. Jones", 50, 1.0f, 2.0f),
new Alien ("Mx. Charm", 70),
new Human,
new Alien,
};
So here, Object is the base class, and Human and Alien are derived classes. Now my problem is that I need to access each of the objects and add extra functionality. As in, I need to access object[0](which is Human) and add whatever needs to be added. So I tried,
Human human0 = (Human)object[0]; // ERROR:'no matching function to call Human::Human(Object*&)'
OR
Human *human0;
human0 = dynamic_cast<Human*>(object[0]); //ERROR: cannot dynamic_cast 'object[0]' (of type 'class Oject*') to type 'class Human*' (source is not polymorphic)'
Human* human0 = (Human*)object[0];Human* human0 = (Human*)object[0];andHuman* human1 = (Human*)object[1], then how do I say "if (object[0]) then - "This is want I want to do"