title: How to create an iterator over elements that match a derived type in C++?
body: <p>I'd like an iterator in C++ that can only iterate over elements of a specific type.   In the following example, I want to iterate only on elements that are SubType instances.</p>
  
  <pre><code>vector&lt;Type*&gt; the_vector;
  the_vector.push_back(new Type(1));
  the_vector.push_back(new SubType(2)); //SubType derives from Type
  the_vector.push_back(new Type(3));
  the_vector.push_back(new SubType(4)); 
  
  vector&lt;Type*&gt;::iterator the_iterator; //***This line needs to change***
  
  the_iterator = the_vector.begin();
  while( the_iterator != the_vector.end() ) {
      SubType* item = (SubType*)*the_iterator;
      //only SubType(2) and SubType(4) should be in this loop.
      ++the_iterator;
  }
  </code></pre>
  
  <p>How would I create this iterator in C++?</p>