title: Is it not possible to construct instances in a loop without a pointer?
body: <p>This code will explode, right? As soon as the loop exits, the original instances will die with all their inner members so if they weren't PODs, any method like <code>do_stuff</code> which requires access to members of <code>B</code> will throw a segmentation fault, correct?</p>
  
  <pre><code>void foo() {
    std::vector&lt;B&gt; bar;
    for (int i = 0; i &lt; 7; i++)
      bar.push_back(B(i, i, i));
    bar[3].do_stuff();
  }
  </code></pre>
  
  <p>So, is there any way to do this without using a pointer? 
  Or do you have to do this:</p>
  
  <pre><code>void foo() {
    std::vector&lt;B*&gt; bar;
    for (int i = 0; i &lt; 7; i++)
      bar.push_back(new B(i, i, i));
    bar[3]-&gt;do_stuff();
    for (int i = 0; i &lt; 7; i++)
      delete bar[i];
  }
  </code></pre>