title: List of pointers to different types of objects
body: <p>What would be the best way to implement a list of pointers to different types in C++?</p>
  
  <p>I thought of doing something like this:</p>
  
  <pre><code>enum MyType {...};
  typedef std::pair&lt;MyType, void*&gt; Ptr;
  std::vector &lt;Ptr&gt; list;
  </code></pre>
  
  <p>And then doing the suitable static typecast as soon as I need to access one of the objects in the list.</p>
  
  <p>Another approach would be having different vectors for each object type:</p>
  
  <pre><code>std::vector&lt;ClassA*&gt; list_a;
  std::vector&lt;ClassB*&gt; list_b;
  ...
  </code></pre>
  
  <p>The issue is that I need to implement a graph where not all vertices have the same type.</p>
  
  <p>EDIT. Performance is critical. The more efficient the code is the better.</p>