Casting base to derived class according to a type flag
Is casting a base class object to a derived class object given a type flag a good programming design?


Usually no.
It usually indicates a badly defined interface in your base class.

A better way to do it will depend on what you want you want to do with it. If you can define an abstract interface with virtual functions that would be the normal way of solving this problem.

But you seem to be using DisplayEventData as simply a bag of properties so maybe there is no generic interface. In which case I would go with a union (but that choice could change quickly based on other information).

struct DisplayEventData   // struct because it is a property bag not a real class.
{
     DisplayEventType   type;
     union
     {
            WindowEventData   win;
            KeyboardEventData key;
            MouseEventData    mouse;
            JoystickEventData joy;
     } data;
};


PS:

This is the wrong cast:

KeyboardEventData* kev = static_cast&lt;KeyboardEventData&gt;(ev.GetEventData());


You should be using dynamic_cast