Event parameters question

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Event parameters question

      Hi everyone!

      I've recently bought this book and it turned out to be well worth the money so far :)

      However, reading Chapter 10 I've came across some doubts about how event parameters are actually managed.
      Every kind of event has different types and number of parameters, but defining different getters for each one would not be a good idea since the EventBase class should then define a big number of virtual functions. I thought about creating maps for each type of parameter which can be defined as needed in the Event classes, each containing a parameter and an ID event listeners can use to retrieve the parameter value, but I'm not sure this is the best solution.

      I'm not a big expert of c++ either, so maybe I'm missing something here ;)
    • Typically you just down-cast cast the event to the appropriate type in the listener's ReceiveEvent() function.

      Source Code

      1. // Note: I don't have the code in front of me, so this may not be verbatim...
      2. virtual void ReceiveEvent(Event* pEvent)
      3. {
      4. SpecialEventOrWhatever* pSpecialEvent = static_cast<SpecialEventOrWhatever*>(pEvent);
      5. DoSomething(pSpecialEvent->GetSomeSpecialValue());
      6. }


      -Rez