title: creating an array of object pointers C++
body: <p>I want to create an array that holds pointers to many object, but I don't know in advance the number of objects  I'll hold, which means that I need to dynamically allocate memory for the array. I have thought of the next code:</p>
  
  <pre><code>ants = new *Ant[num_ants];
  for (i=1;i&lt;num_ants+1;i++)
  {
      ants[i-1] = new Ant();
  }
  </code></pre>
  
  <p>where <code>ants</code> is defined as <code>Ant **ants;</code> and <code>Ant</code> is a class.</p>
  
  <p>Will it work?</p>