how to dynamically declare an array of objects with a constructor in c++
<p>I was wondering if it was possible to create an array of objects when the object needs things passed into it for the constructor.  I want something like this:</p>

<pre><code>MyClass *myVar;
myVar = new MyClass[num];  // I would like to specify the array size after declaration
int i = 0;
for(i = 0;i &lt; num;i++)
   myVar[i] = new MyClass(0,0);  // I would also like to populate the array with new objects
</code></pre>

<p>I know that this works:</p>

<pre><code>MyClass *myVar;
myVar = new MyClass[num];
</code></pre>

<p>but this only works when the constructor has nothing passed into it.  Is what I am trying to do possible?  If so, how do I do it?</p>

<p>EDIT:  I found out how to do it with using arrays.  Here is how I did it:</p>

<pre><code>MyClass **myVar;
myVar = new MyClass *[num];
for(i = 0;i &lt; num;i++)
   myVar[0] = new MyClass(0,0);
</code></pre>

<p>I would use vectors and such but my teacher has told us to use basic arrays whenever possible.  The above solution I actually got from some code my teacher wrote.  Thank you all for your help!</p>
