So presume I have a base class Object and an abstract base class Collidable. (Object containing position information and such and Collidable containing virtual void Collide(Object object) = 0. There will then be child classes that inherit Object, but only certain ones will also inherit Collidable. So my question is, if one of those collidable child classes were to check through a list of Object inherited classes, how might it determine if they also inherit Collidable so that they collide with each other and not with objects that aren't collidable?
(To give a more visual look at my question)
class Object
{
protected:
Position myPosition;
public:
Object(void);
~Object(void);
}
class Collidable
{
protected:
/* ... */
public:
virtual void Collide(Object& object) = 0;
Collidable(void);
~Collidable(void);
}
class Grass : public Object
{
private:
/* ... */
public:
Grass(void);
~Grass(void);
}
class Wall : public Object, public Collidable
{
private:
/* ... */
public:
virtual void Collide(Object& object) { /* Collide logic */ }
Wall(void);
~Wall(void);
}
class Monster : public Object, public Collidable
{
private:
/* ... */
public:
virtual void Collide(Object& object) { /* Collide logic */ }
Monster(void);
~Monster(void);
}
int main()
{
Monster creature;
Object* objects[] = { /* list of Grass, Wall, and Monster classes */ };
for(int i = 0, i < objects.size(); i++)
{
//Logical error: not every object is collidable
creature.Collide(&objects[i]);
}
}
So here, I have a list of Wall Monster and Grass classes, but Grass is not collidable, however, let's say that it needs to stay in the array with the other classes. How might I determine if the class in the array is Collidable?
( I do apologize if I am somehow way off key here, but I have been researching and studying a bunch of object oriented things recently so I am still in my learning phase here. )