title: How do I implement a display function for a binary search tree?
body: <p>How do I implement a display function for a binary search tree of strings if display is passed as a function pointer to function inorder?</p>
  
  <pre><code>typedef void (*FunctionType)(TreeItemType&amp; anItem);
  void display(TreeItemType&amp; anItem);
  void BinarySearchTree::inorder(TreeNode *treePtr, 
                           FunctionType visit)
  {   if (treePtr != NULL)
      {   inorder(treePtr-&gt;leftChildPtr, visit);
          visit(treePtr-&gt;item);
          inorder(treePtr-&gt;rightChildPtr, visit);
      } // end if
  } // end inorder
  </code></pre>
  
  <p>I've tried to write something like:</p>
  
  <pre><code>cout &lt;&lt; anItem;
  </code></pre>
  
  <p>in the body of display but it doesn't work.  TreeItemType is a string so do I need to overload the &lt;&lt; operator or = operator to convert from TreeItemType to string?  I have researched function pointers and can't figure out how to use:</p>
  
  <pre><code>visit(treePtr-&gt;item);
  </code></pre>
  
  <p>to display the tree's item (which is a string).</p>
  
  <pre><code>int main()
  {
      BinarySearchTree tree;
      TreeItemType item = "20";
      tree.searchTreeInsert(item);
      tree.inorderTraverse(display); // call to inorderTraverse calls inorder
      return 0; // indicates successful completion
  } // end function main
  
  void display(TreeItemType&amp; anItem)
  {
      cout &lt;&lt; anItem;
  }
  </code></pre>
  
  <p>Definition of TreeItemType:</p>
  
  <pre><code>typedef string TreeItemType;
  </code></pre>