title: STL Iterator Inheritance : 'value_type' does not name a type
body: <p>I am stuck trying to understand where this error comes from:</p>
  
  <pre><code>error: ‘value_type’ in ‘struct std::iterator_traits&lt;sha::Vector&lt;int&gt;::h_iterator&gt;’ does not name a type
  </code></pre>
  
  <p>I am  trying to create a <code>std::vector</code> wrapper and inherit iterator as well.
  I don't get why the compilator cannot infer the 'value_type' or 'difference_type'.</p>
  
  <p>Here is my class definition:</p>
  
  <pre><code>  template &lt;typename T&gt;
    class Vector
    {
      public:
      explicit Vector(std::initializer_list&lt;T&gt; init) : data(init) {}
      ~Vector() {}
  
    class h_iterator : std::iterator&lt;std::random_access_iterator_tag, T&gt;
    {
      public:
        h_iterator(typename std::vector&lt;T&gt;::iterator it,
                   Vector&lt;T&gt;* owner) :
          it(it), owner(owner) {}
  
        T operator *() const { return *it; }
        const h_iterator &amp;operator ++() { ++it; return *this; }
        h_iterator operator ++(int) { h_iterator copy(*this); ++it; return copy; }
        const h_iterator &amp;operator --() { --it; return *this; }
        h_iterator operator --(int) { h_iterator copy(*this); --it; return copy; }
        h_iterator&amp; operator =(const h_iterator&amp; other){ this-&gt;it =other.it; return *this;}
  
        bool operator ==(const h_iterator &amp;other) const { return it == other.it; }
        bool operator !=(const h_iterator &amp;other) const { return it != other.it; }
        bool operator  &lt;(const h_iterator &amp;other) const { return it  &lt; other.it; }
        bool operator  &gt;(const h_iterator &amp;other) const { return it  &gt; other.it; }
        bool operator &lt;=(const h_iterator &amp;other) const { return it &lt;= other.it; }
        bool operator &gt;=(const h_iterator &amp;other) const { return it &gt;= other.it; }
  
        h_iterator operator +(const long int &amp;delta) const
        {
          h_iterator copy(*this);
          it += delta;
          return copy;
        }
  
        h_iterator&amp; operator +=(const long int&amp; delta)
        {
          it = it + delta;
          return *this;
        }
  
        h_iterator operator -(const long int &amp;delta) const
        {
          h_iterator copy(*this);
          it -= delta;
          return copy;
        }
  
        h_iterator&amp; operator -=(const long int&amp; delta)
        {
          it = it - delta;
          return *this;
        }
  
        T operator [](const long int &amp;delta) const { return *(it + delta); }
  
      private:
        typename std::vector&lt;T&gt;::iterator it;  // Iterator
        Vector&lt;T&gt;* owner;                      // Cannot be null as long as the iterator is valid
    };
  
    // Preserve normal iterator accesses
    typename std::vector&lt;T&gt;::iterator begin() { return data.begin(); }
    typename std::vector&lt;T&gt;::iterator end() { return data.end(); }
  
    const typename std::vector&lt;T&gt;::iterator cbegin() const { return data.cbegin(); }
    const typename std::vector&lt;T&gt;::iterator cend() const { return data.cend(); }
  
    // Observale iterator
    h_iterator h_begin() { return h_iterator(data.begin(), this); }
    h_iterator h_end() { return h_iterator(data.end(), this); }
  
    // Implement Meta-Language functions
    //...
  
  private:
    Vector() {}
    Vector operator=(Vector&amp;) {} // Not Implemented
  
    std::vector&lt;T&gt; data;            // Vector wrapper
  };
  </code></pre>
  
  <p>Here is the code that makes the compilation failed:</p>
  
  <pre><code>typedef Vector&lt;int&gt; Container;
  typedef Container::h_iterator IT;
  typedef std::less&lt;typename 
  std::iterator_traits&lt;Vector&lt;int&gt;::h_iterator&gt;::value_type&gt; Compare;
  </code></pre>
  
  <p>Why does this compile error happen?</p>