Create an array of class objs
<p>Consider following class</p>

<pre><code>class test
{
public:
test(int x){ cout&lt;&lt; "test \n"; }

};
</code></pre>

<p>Now I want to create array of 50 objects of class test . I cannot change class test.</p>

<p>Objects can be created on heap or stack.</p>

<p>Creating objs on stack is not possible in this case since we dont have default constructor in class</p>

<pre><code>test objs(1)[50]; /// Error...
</code></pre>

<p>Now we may think of creating objs on heap like this..</p>

<pre><code>test ** objs = NULL;
objs = (test **) malloc( 50 * sizeof (test *));
for (int i =0; i&lt;50 ; ++ i)
{
   objs[i] = new test(1);
}
</code></pre>

<p>I dont want to use malloc .Is there any other way??</p>

<p>If you guys can think of some more solutions , please post them...</p>
