Dave said:
Using RTTI to implement polymorphic behavior is usually an indication
of a design problem. Unless you're serializing/unserializing objects,
RTTI is seldom necessary.
Perhaps you can explain more about the problem you are trying to
solve?
I have a kind of ... game. This game gets messages about UI events
from a platform dependant layer. Messages are various but simple, like:
class some_display_event
{
public:
virtual ~some_display_event() { };
};
class reconfigure_event : public some_display_event
{
public:
int width;
int height;
reconfigure_event(int _width, int _height) :
width(_width), height (_height) { };
private:
reconfigure_event();
};
class quit_event : public some_display_event { };
....
Game knows how to use the UI, but the UI knows nothing about the game;
of course they both speak the same message-passing language. The game
then polls the UI from time to time:
bool loop_endlessly = true;
while(loop_endlessly)
{
...
some_display_event * event = display.check_events();
if(event)
{
if(reconfigure_event * re =
dynamic_cast<reconfigure_event *>(event))
{
reconfigure(re->width, re->height);
delete re;
}
else if(quit_event * qe = dynamic_cast<quit_event *>(event))
{
delete qe;
loop_endlessly = false;
}
else
{
delete event;
throw 38122178;
}
}
...
}
Now this game can also draw nice things, consisting of nice and simple
drawing primitives. These primitives are stored in containers, so they
must be ... polymorphic. And here we go again!
What do you say?