title: Passing References to Member Functions
body: <p>I've been working with a doubly-threaded BST in C++, and I thought it would be cool to separate my visitor functions from my various traversals. However I can't figure out how to properly pass references to member functions into my traversal functions. Here is a massively simplified version of my problem:</p>
  <pre><code>class foo {
  public:
      foo() {};
      ~foo() {};
  
      void print(int x) const { //visitor
          cout &lt;&lt; x &lt;&lt; endl;
      }
  
      void traverse(void (*visitor)(int)) { //traversal
          for (int i = 0; i &lt; 9; i++)
              visitor(myAry[i]);
      }
  
      void printAll() { //function calling the traversal and passing it a reference to the visitor
          traverse(&amp;print);
      }
  
      int myAry[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  };
  </code></pre>
  <p>The problem of course comes in the <code>traverse(&amp;print);</code> statement.</p>
  <p>Any clues what's going wrong, or what I could try differently to achieve the same effect?</p>