title: Passing a function object as function argument
body: <p>I would like to simply pass my initialized function object to my own function in several ways.</p>
  
  <p>I did not find any examples with own functions just with "for_each" but as far as i understand it should work the same way.</p>
  
  <pre><code>void    f(int&amp; n, void (*g)(int&amp; m) ){ g(n);};
  
  class TEST{
  public:
      int init=0;
      TEST(int _init):init(_init){}
      void    operator() (int&amp; m) {m+=init;}
  
  };
  
  int main(int argc, char *argv[])
  {
      int k, m;
      cin &gt;&gt; k &gt;&gt; m;
  
      TEST    mytest(m); // OK, creates object with initialization
      mytest(m);         // OK, using initialized object's "operator()"
  
      f(k,mytest);       //  error: cannot convert 'TEST' to
                         //  'void (*)(int&amp;)' for argument '2'to
                         //  'void f(int&amp;, void (*)(int&amp;))'
  
      f(k,TEST(m));      //  error: cannot convert 'TEST' to
                         //  'void (*)(int&amp;)' for argument '2'to
                         //  'void f(int&amp;, void (*)(int&amp;))'
  
      return 0;
  }
  </code></pre>