title: how to initialize an array of objects in a constructor in c ++
body: <p>I try to put an array of objects as a argument,
  I know that you can initialize them separately with</p>
  <blockquote>
  <p>constructorName (className array [], double arg2): name1 (arg1), name2(arg2){...}</p>
  </blockquote>
  <p>But I can't do that with an array of objects, is there any other way to do this?</p>
  <p>code example:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  class Atlet{
      private:
          string name;
          int number;
          string nacionality;
          double time;
      public:
          Atlet(string n, int num, string nacio, double t){
              name = n;
              number = num;
              nacionality = nacio;
              time = t;                
          }
          string getName(){
              return name;
          }
  };
  
  class Race{
      private:
          double distance;
          Atlet runners[];
      public:
          //how to initalize arrays of objects here .
  
          Race( Atlet arr[], double dist): runners(arr), distance(dist){
              runners = arr;
              distance = dist;          
          } 
  };
  </code></pre>
  <p>test.cpp program.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &quot;bible.cpp&quot;
  using namespace std;
  
  int main(){
      Atlet t1 = Atlet(&quot;Usaimbol&quot;,12,&quot;Madagascar&quot;, 10.21);
      Atlet t2 = Atlet(&quot;Juan&quot;,15,&quot;USA&quot;, 10.54);
  
      Atlet comps[] = {t1, t2};
      Race race1 = Race(comps, 120.00);
      return 0;
  }
  </code></pre>
  <p>I try to  make this, but:
  <a href="https://i.stack.imgur.com/xvq8Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xvq8Z.png" alt="console bug" /></a></p>