title: Storing a List of Objects
body: <p>Let's say I have a generic Object class, and a generic List class. I want to maintain a list of these Objects. Should I store them as <code>List&lt;Object&gt;</code> or <code>List&lt;Object*&gt;</code>?</p>
  
  <p>If I use <code>List&lt;Object&gt;</code> and I have a method like:</p>
  
  <pre><code>if(some_condition) {
      Object obj;
      myObjectList.append(obj);
  }
  </code></pre>
  
  <p>And my list class only keeps a reference to the object, so as soon as that if statement terminates, the object is destroyed, and the object I pushed becomes invalid. So then I end up doing something like:</p>
  
  <pre><code>Object *obj = new Object;
  myObjectList.append(*obj);
  </code></pre>
  
  <p>So that it doesn't get destroyed. But now the objects are undeletable, no? Because now they're stored safely in the List as Objects, not pointers to Objects, so I can't call delete on them... or will they automatically be destroyed when they're popped from the list?</p>
  
  <p>In that case, I should probably use <code>List&lt;Object*&gt;</code> and delete them from the list when I'm done with them, no?</p>
  
  <p>So confused... I'm sure I have a fundamental misunderstanding here somewhere.</p>