title: How to overload the indirection operator? (C++)
body: <p>I'm trying to create an iterator class as a member-class for a list class, and am trying to overload the indirection operator (*) to access the list it's pointing to:</p>
  
  <pre><code>template&lt;class T&gt;
  T list&lt;T&gt;::iterator::operator*(iterator&amp; iter)
  {
      return ((iter.lstptr)-&gt;current)-&gt;data;
  }
  </code></pre>
  
  <p>where <code>lstptr</code> is a pointer to a list, <code>current</code> is a pointer  to a node class, and the node class contains the data member <code>data</code> of type <code>T</code>.</p>
  
  <p>Iterator is declared like this:</p>
  
  <pre><code>template&lt;class T&gt;
  class list
  {
  public:
  class iterator;
  };
  
  template&lt;class T&gt;
  class list&lt;T&gt;::iterator
  {
  //stuff
  };
  </code></pre>
  
  <p>I am able to compile the function definition of the overloaded operator* fine, but when I try to do something like:</p>
  
  <pre><code>list&lt;int&gt; lst1;
  lst1.add(6);
  list&lt;int&gt;::iterator IT;
  IT = lst1;
  //everything above this point compiles fine
  int a = *IT; //error here (line fourteen)
  </code></pre>
  
  <p>The error I get says &lt;1> that I am using an illegal indirection, and &lt;2> that it cannot convert from list::iterator to int.  Both errors occur on line fourteen.</p>
  
  <p>Does anybody know what I am doing wrong and how I can overload the indirection operator correctly?</p>
  
  <p>NB: If you need to see more code, tell me which part, because I don't want to put th entire code up here because it's abot 205 lines, and 204 of those lines don't (I think) have any errors.</p>