title: STL List - Datatype as a pointer object
body: <p>I'm having a problem using inheritance and the STL list library...</p>
  
  <p>Say, I have an abstract base class with two derived classes (where all comparison operators are defined). The list is declared as </p>
  
  <pre><code>list&lt;StoreItem*&gt; items;
  </code></pre>
  
  <p>I'm inserting a derived class (of the abstract base class, StoreItem) called either Food or Clothing. I make a new StoreItem pointer that's about to be inserted:</p>
  
  <pre><code>StoreItem* item = new Food(arguments here);
  </code></pre>
  
  <p>Now, I'm wanting to insert this new item (in order) to the list, and my attempt is this:</p>
  
  <pre><code>list&lt;StoreItem*&gt;::iterator iter;
  for (iter = inventory.begin(); iter != inventory.end(); iter++)
  {
      if (*item &lt; **iter)
          break; // break out to insert
  }
  
  inventory.insert(iter, item);
  </code></pre>
  
  <p>Is there anything I'm doing wrong? Also, how would I pull the information from the inventory? (ex: Food tempFruit(**iter) using the copy constructor).</p>
  
  <p>Thank you in advance! Have a good day.</p>