>
There a few ways, but first a question....
Why do you need to check what the type is?
Asking an object (regardless that we can using built in or home grown
methods) what type it is, is usually a Design Flaw.
'Tell don't ask' is a better safer approach....
door.handleActionEvent(doorEvent);
instead of
if (door.isClosedDoor() )
{
door.close();
}
else
{
door.open();
}
Andrew
Well the problem is a bit different than example. I'm making an RPG
game.
// Base class for all tiles
class Tile { ... };
// class for all Accesible Tiles
class Accesible : public Tile
// class for all Inaccesible Tiles
class Inaccesible : public Tile
Well and from those 2 subclasses - Acc and Inacc are derived all
classes, even the Door :)
And when generating Map I need to recognize wheter Tile is accesible or
not.
Ehm... I guess it would be OK to have member in tile bool isAccesible.
So this one is solved.
But still I sometimes it'd be useful to know the type it. You see. I
may have few Tile derivates like Grass, Flowers, Sand etc. And it'd be
useful to group them in one class for example Ground. So when I will
need to work with all the Grounds I will not have to write a lot ifs.