Skip to content

using acebutton in a class with a non static callback function #89

Answered by bxparks
patrickwasp asked this question in Q&A
Discussion options

You must be logged in to vote

(Edit: Added some missing words in my initial post for clarity, inside [])

There are many ways to avoid passing ui as a global variable. The appropriate solution will depend on the complexity of the rest of the application. Here are a few off the top of my head:

  1. Use constructor dependency injection to pass ui into ButtonHandler:
class ButtonHandler : public IButtonHandler {
  public:
      ButtonHandler(UserInterface* ui) : _ui(ui) {
       ...
    }

  private:
    Userinterface* _ui;
};
  1. Make UserInterface implement the IButtonHandler interface directly, and use setIEventHandler() to inject itself into the AceButton:
class UserInterface : public IButtonHandler {
  public:
    void Setup

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by patrickwasp
Comment options

You must be logged in to vote
1 reply
@bxparks
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants