title: C++/Arduino Pass a function as argument
body: <p>I am trying to create a callback style API and am fairly new to C++. I keep getting the error <code>error: invalid use of non-static member function</code> but am not sure the next steps. I would like to have the ability to pass an member function as an argument to another class.</p>
  
  <p>The code is something like</p>
  
  <pre><code>class Button {
    int buttonDownTime = 0;
    int debounceTime = 2000;
  
    ...
  
    template&lt;typename Callback&gt;
    void debounce(Callback func) {
      if (millis() - buttonDownTime &gt; debounceTime) {
        func();
      }
    }
  }
  
  class Player {
    int playerCount = 0;
  
    void incriment() {
      playerCount++;
    }
  }
  
  void loop() {
  
    ...
  
    button.debounce(player.incriment);
  }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>So I want to thank everyone for the awesome answers so far but I learned something since posting. Arduino's AVR does not include C++'s <code>&lt;functional&gt;</code>. Is this a possible thing to do without that library?</p>
  
  <p>Thank you again!</p>