News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

C++ tips - Callbacks and multiple inheritance, part II

Started by ben2ong2, October 07, 2006, 04:01:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ben2ong2

This example is based upon "Subobject Members", Stephen Dewhurst,
C++ Report, V5 N3. This is part 2 of a multipart example.

In this example, assume that the engine-button example of the previous
tip are extended two include two buttons. One will be for starting the
engine, one for stopping. Using the design technique of the previous
example, one would have:

.................................................................

class StartButtonCallback : public ButtonCallback {
  public:
    void callback () { start (); }
    virtual void start () = 0;
};

.................................................................

class StopButtonCallback : public ButtonCallback {
  public:
    void callback () { stop (); }
    virtual void stop () = 0;
};

.................................................................

class Engine : public StartButtonCallback,
          public StopButtonCallback {
    // ...
  public:
    void start ();
    void stop  ();
};

.................................................................

The first drawback with this approach is the global namespace
pollution introduced by the two callback classes. In addition,
these classes are unlikely to be reused except with engines.
You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login