title: Overloading the dereference operator for a custom iterator
body: <p>This is the first time I've ever played with an iterator so there's probably significant errors. I'm attempting to make an inorder iterative iterator class to work in conjunction with my threaded binary search tree. So the iterator is working over nodes. I only need the iterator to go through my tree in order so I can print all the values and the frequencies of each node. However my dereference doesn't seem to be working probably. This is the method that's giving me trouble:</p>
  
  <pre><code>//-------------------------- inOrderTraverse ------------------------------------
  template &lt;typename T&gt;
  void ThreadedBST&lt;T&gt;::inOrderTraverse() {
      InorderIterator&lt;T&gt;* iter = new InorderIterator&lt;T&gt;(root);
      ++iter;
  
      while ((*iter) != NULL)
      {
          cout &lt;&lt; (*iter)-&gt;getItem() &lt;&lt; " " &lt;&lt; (*iter)-&gt;getFrequency() &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>Particularly the while loop is throwing compiler errors. Here is the exact error:</p>
  
  <p>error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'InorderIterator'</p>
  
  <p>I figured the dereference would bring the node out so I'd actually be comparing the node != NULL but that's not what the error message leads me to believe. Here's the full Iterator class:</p>
  
  <pre><code>#ifndef INORDERITER_H
  #define INORDERITER_H
  
  #include &lt;iostream&gt;
  #include "ThreadedBST.h"
  using namespace std;
  
  //---------------------------------------------------------------------------
  // InorderIterator&lt;T&gt; class: 
  //   -- 
  //
  // Assumptions:
  //   -- &lt;T&gt; implements it's own comparable functionality
  //---------------------------------------------------------------------------
  
  template &lt;typename T&gt;
  class InorderIterator {
  
  public:
      InorderIterator(node&lt;T&gt; *); //constructor
      InorderIterator&lt;T&gt;&amp; operator++();
      node&lt;T&gt;&amp; operator*();
      const node&lt;T&gt;&amp; operator*() const;
  
  private:
      node&lt;T&gt;* begin;
      node&lt;T&gt;* curr;
      node&lt;T&gt;* prev;
      node&lt;T&gt;* temp;
  };
  
  template &lt;typename T&gt;
  InorderIterator&lt;T&gt;::InorderIterator(node&lt;T&gt;* root) {
      begin = root;
      temp = NULL;
  
      while (begin-&gt;leftChild != NULL) {
          begin = begin-&gt;leftChild;
      }
  }
  
  template &lt;typename T&gt;
  InorderIterator&lt;T&gt;&amp; InorderIterator&lt;T&gt;::operator++() {
      if (temp == NULL)
          temp = begin;
      else if (rightChildThread) {
          prev = temp;
          temp = temp-&gt;rightChild;
      }
      else {
          prev = temp;
          temp = temp-&gt;rightChild;
  
          while (!temp-&gt;rightChildThread &amp;&amp; (temp-&gt;leftChild-&gt;getItem() != prev-&gt;getItem())) {
              temp = temp-&gt;leftChild;
          }
      }
  
      curr = temp;
      return *this;
  }
  
  template &lt;typename T&gt;
  node&lt;T&gt;&amp; InorderIterator&lt;T&gt;::operator*() {
      return *curr;
  }
  
  template &lt;typename T&gt;
  const node&lt;T&gt;&amp; InorderIterator&lt;T&gt;::operator*() const {
      return *curr;
  }
  
  #endif
  </code></pre>
  
  <p>Here's the node class if it's relevant for any reason:</p>
  
  <pre><code>#ifndef NODE_H
  #define NODE_H
  
  #include &lt;iostream&gt;
  using namespace std;
  
  //---------------------------------------------------------------------------
  // node&lt;T&gt; class: 
  //   -- 
  //
  // Assumptions:
  //   -- &lt;T&gt; implements it's own comparable functionality
  //---------------------------------------------------------------------------
  
  template &lt;typename T&gt;
  class node {
  
  public:
      node&lt;T&gt;* leftChild;
      node&lt;T&gt;* rightChild;
      bool leftChildThread;
      bool rightChildThread;
      node(T value); //constructor
      node(T value, node&lt;T&gt;*, node&lt;T&gt;*, bool, bool); //secondary constructor
      node(const node&lt;T&gt;&amp;); //copy constructor
      void decrementFrequency(); //decrements by 1 the frequency
      void incrementFrequency(); //increments by 1 the frequency
      int getFrequency(); //returns the frequency
      T getItem(); //returns the item
  
  private:
      T item;
      int frequency;
  };
  
  //-------------------------- Constructor ------------------------------------
  template &lt;typename T&gt;
  node&lt;T&gt;::node(T value) {
      item = value;
      frequency = 1;
  
  }
  
  //-------------------------- Secondary Constructor ------------------------------------
  template &lt;typename T&gt;
  node&lt;T&gt;::node(T value, node&lt;T&gt;* left, node&lt;T&gt;* right, bool leftThread, bool rightThread) {
      item = value;
      frequency = 1;
      leftChild = left;
      rightChild = right;
      leftChildThread = leftThread;
      rightChildThread = rightThread;
  }
  
  //-------------------------- Copy ------------------------------------
  template &lt;typename T&gt;
  node&lt;T&gt;::node(const node&lt;T&gt;&amp; copyThis) {
      item = copyThis.value;
      frequency = copyThis.frequency;
  }
  
  //-------------------------- decrementFrequency ------------------------------------
  template &lt;typename T&gt;
  void node&lt;T&gt;::decrementFrequency() {
      frequency--;
  }
  
  //-------------------------- incrementFrequency ------------------------------------
  template &lt;typename T&gt;
  void node&lt;T&gt;::incrementFrequency() {
      frequency++;
  }
  
  //-------------------------- getFrequency ------------------------------------
  template &lt;typename T&gt;
  int node&lt;T&gt;::getFrequency() {
      return frequency;
  }
  
  //-------------------------- getItem ------------------------------------
  template &lt;typename T&gt;
  T node&lt;T&gt;::getItem() {
      return item;
  }
  
  #endif
  </code></pre>