title: Filling up a vector of pointers
body: <p>please excuse my noobie question..</p>
  
  <p>I have :</p>
  
  <pre><code>class A;
  {
      public:
      A(int i) : m_i(i) {}
      int m_i;
  }
  
  A newA(i);
  {
      return A(i);
  }
  </code></pre>
  
  <p>And I want to fill the following vector, but using a loop where an object A is created with a function (newA):</p>
  
  <pre><code>vector&lt;A*&gt; list;
  
  for (int i=0 ; i&lt;3; ++i) {  A a = newA(i);  list.push_back(&amp;a); }
  </code></pre>
  
  <p>That works if I use a <code>vector&lt;A&gt;</code> but not with a <code>vector&lt;A*&gt;</code> since all I do is changing the value at &amp;a and pushing 3 times the same pointer &amp;a.</p>
  
  <p>How can I do so that I create a new A every time, and not change the value of the same pointer.</p>
  
  <p>I came up with the following but I hope it's not the only way, since it includes dynamic allocation..</p>
  
  <pre><code>A newA(i);
  {
      return A(i);
  }
  
  vector&lt;A*&gt; list;
  
  for (int i=0 ; i&lt;3; ++i)
  {
      A a = newA(i);
      list.push_back(new A(a));
  }
  </code></pre>
  
  <p>Note that class A is actually huge in memory, hence the pointers.</p>