title: C++ std::set<Vertex> iterator with custom Vertex class
body: <p>I am confused with implementing iterators for custom classes.  I'm trying to implement an iterator for std::set where my Vertex class is declared as:</p>
  
  <pre><code>class Vertex{                                                   
  public:
      int i, j; 
      std::set&lt;Vertex*&gt; adj; //references to adjacent vertices
  
      Vertex();
      ~Vertex();
      //end constructors
  
      /** must overload for set&lt;Vertex&gt; to function */
      const bool operator &lt; (const Vertex &amp;o) const;
  
  };//END class Vertex
  </code></pre>
  
  <p>But if I define</p>
  
  <pre><code>iterator&lt;Vertex*&gt; begin(){
      return iterator&lt;Vertex*&gt;( *this, 0 ); 
  }
  iterator&gt;Vertex*&gt; end(){ 
      return iterator&lt;Vertex*&gt;( *this, sizeof(Vertex) ); 
  }
  </code></pre>
  
  <p>So that I can hopefully iterate like:</p>
  
  <pre><code>set&lt;Vertex*&gt;::iterator it;
      //for all vertices adjacent of cur
      for(it = cur.begin(); it != cur.end(); it++){
          //...
      }
  </code></pre>
  
  <p>And receive these errors:</p>
  
  <pre><code>In file included from Vertex.cc:8:0:
  Vertex.h:50:22: error: wrong number of template arguments (1, should be 5)
   std::iterator&lt;Vertex*&gt; begin();
                        ^
  In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_algoba
  se.h:65:0,
                   from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_tree.h
  :61,
                   from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\set:60,
                   from Vertex.h:10,
                   from Vertex.cc:8:
  c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_iterator_base_types.h:118:12
  : error: provided for 'template&lt;class _Category, class _Tp, class _Distance, cla
  ss _Pointer, class _Reference&gt; struct std::iterator'
       struct iterator
              ^
  In file included from Vertex.cc:8:0:
  Vertex.h:50:31: error: invalid type in declaration before ';' token
   std::iterator&lt;Vertex*&gt; begin();
                                 ^
  Vertex.h:51:22: error: wrong number of template arguments (1, should be 5)
   std::iterator&lt;Vertex*&gt; end();
  
  &lt;additional errors&gt;
  
  ss _Pointer, class _Reference&gt; struct std::iterator'
       struct iterator
              ^
  Vertex.cc:114:29: error: invalid use of 'this' in non-member function
    return iterator&lt;Vertex*&gt;( *this, 0 );
                               ^
  Vertex.cc: At global scope:
  Vertex.cc:116:1: error: invalid use of template-name 'std::iterator' without an
  argument list
   iterator&gt;Vertex*&gt; end(){
   ^
  Vertex.cc: In function 'int begin()':
  Vertex.cc:115:1: warning: control reaches end of non-void function [-Wreturn-typ
  e]
   }
   ^
  make: *** [Vertex.o] Error 1
  </code></pre>
  
  <p>I need help figuring out how to go about doing this; I've found most tutorials/links confusing as well.  Note: I'm not using C++11</p>