title: How to initialize an array of objects of a parameterized constructor
body: <p>I need to initialize  an array of objects of a parametrized constructor . How can i do it in best possible way ? </p>
  
  <pre><code>   # include&lt;iostream&gt;
     # include&lt;conio.h&gt;
     # include&lt;stdio.h&gt;
  
     using namespace std;
  
     class A
     {
      public:
      int a;       
      A();
      A(int x)
      {
       a=x;
      }      
     };
     int main()
     {
      A *a1,a2(1);
      a1 = (A*)malloc(sizeof(A)*10); // equivalent to A[10]. 
      for(int i=0;i&lt;10;i++) a1[i]=a2; // Initialization is important in any program.
      for(int i=0;i&lt;10;i++) cout&lt;&lt;a1[i].a; 
      getch(); 
      return 0;   
     }
  </code></pre>
  
  <p>This does work but is there some other way better than this ?</p>