Apparently your implementation of a GUI features different types of controls (such as
CButton
) that are all derived from the common base class,
CControl
. Moreover, you have a class
CForm
that is a container for such GUI controls. On a sidenote I would advise you to put that class into the
GUI
namespace.
Further you have an event listener whose purpose is to check on input messages and other kinds of events, and relate them to the forms and GUI controls that may be the target of these messages.
There are a couple of things you must do:
1. Since
CControl
is supposed to be used as a base clase, it
must have a virtual destructor! Depending on your settings, the compiler may create a default constructor for you, but to be sure you should define one yourself.
2. Similarly, since
CControl
is supposed to be a base class, your
CForm
class must store its controls as a list of
pointers to CControl
, not as
CControl
instances!
3. Again, similarly, since
CControl
is used as a base class and other controls derive from it, the methods that are supposed to show different behaviour for different controls must be declared
virtual
in the base class, and have a virtual override in the derived class.
4. The event listener must send event information to all relevant controls. It may not and should not need to know which control is actually interested in any particular event, so there's basically two ways to achieve this:
(a) broadcast all events to all controls and let them decide - this adds the problem of preventing multiple controls to react to a single event (unless that was the purpose)
(b) have the controls 'tell' the event listener what events they're interested in, so the listener only sends out the events to the relevant controls. This principle is known as the
Observer Pattern[
^]