title: C++ function accepting function pointer and non-static member function as parameter
body: <p>I built an interface taking pointers to functions. Sometimes this calculation depends on state, which I want to encapsulate in a class and pass its method:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  
  class Printer {
  public:
      static void print(int i) {  // Want to get rid of the static
          std::cout &lt;&lt; i &lt;&lt; "\n";
      }
  };
  
  
  template&lt;typename int_func&gt;
  void with_1(int_func func) {
      func(1);
  }
  
  
  int main(int argc, char const *argv[]) {
      Printer printer;
      with_1(printer.print);
      return 0;
  }
  </code></pre>
  
  <p>I need non-static methods (and would even prefer overloading <code>operator()</code>). However removing the static results in <code>error: a pointer to a bound function may only be used to call the function</code>.</p>
  
  <p>I could use a dummy like this:</p>
  
  <pre><code>Printer printer;
  void dummy(int i) {
      printer.print(i);
  }
  
  
  int main(int argc, char const *argv[]) {
      with_1(dummy);
      return 0;
  }
  </code></pre>
  
  <p>But that does not look elegant to me. Can I write a template that accepts both, function pointers and non-static methods? Or is there even a better design pattern for my problem?</p>