title: How to reimplement iterator of a class that contains STL container of pointers in C++
body: <p>I have a class that contains a vector of pointers to another class:</p>
  
  <pre><code>class B {};
  
  class A {
      std::vector&lt;B*&gt; data_;
  };
  </code></pre>
  
  <p>and I want to provide the user with an iterator. I thought on using a <code>typedef std::vector&lt;B*&gt;::iterator iterator</code> inside the class but that comes with the problem that <code>iterator::operator*()</code> returns a <code>B*</code> and I want it to completely hide the internal representation to the user.</p>
  
  <p>I did not find a way to reimplement the <code>operator*</code> and it has occured to me that maybe the only solution is to nest a class with an iternal reference to the STL iterator:</p>
  
  <pre><code>class B {};
  
  class A {
      std::vector&lt;B*&gt; data_;
      class iterator {
          std::vector&lt;B*&gt;::iterator it;
          B&amp; operator*();
          ...
      };
  };
  </code></pre>
  
  <p>But I wanted to know, is there any other way that is more elegant in order to acomplish this? My approach implies reimplementing all member functions just to call the equivalent ones in <code>std::vector&lt;&gt;::iterator</code>, except for the already mentioned operator.</p>
  
  <p>Thanks!</p>