title: c++ templated container scanner
body: <p>here's today's dilemma:</p>
  
  <p>suppose I've </p>
  
  <pre><code>class A{
    public:
     virtual void doit() = 0;
  }
  </code></pre>
  
  <p>then various subclasses of A, all implementing their good doit method. Now suppose I want to write a function that takes two iterators (one at the beginning of a sequence, the other at the end). The sequence is a sequence of A subclasses like say <code>list&lt;A*&gt;</code> or vector... The function should call all the doit methods while scanning the iterators... How to do this? I've thought of:</p>
  
  <pre><code>template&lt;typename Iterator&gt; void doList(Iterator &amp;begin, Iterator &amp;end) {
      for (; begin != end; begin++) {
          A *elem = (serializable*) *begin;
          elem.doIt();
      }
  }
  </code></pre>
  
  <p>but gives weird errors... do you have better ideas or specific information? Is it possible to use <code>list&lt;A&gt;</code> instead of <code>list&lt;A*&gt;</code>?</p>