title: C++: constructor initializer for arrays
body: <p>I'm having a brain cramp... how do I initialize an array of objects properly in C++?</p>
  
  <p>non-array example:</p>
  
  <pre><code>struct Foo { Foo(int x) { /* ... */  } };
  
  struct Bar { 
       Foo foo;
  
       Bar() : foo(4) {}
  };
  </code></pre>
  
  <p>array example:</p>
  
  <pre><code>struct Foo { Foo(int x) { /* ... */  } };
  
  struct Baz { 
       Foo foo[3];
  
       // ??? I know the following syntax is wrong, but what's correct?
       Baz() : foo[0](4), foo[1](5), foo[2](6) {}
  };
  </code></pre>
  
  <p><strong>edit:</strong> Wild &amp; crazy workaround ideas are appreciated, but they won't help me in my case. I'm working on an embedded processor where std::vector and other STL constructs are not available, and the obvious workaround is to make a default constructor and have an explicit <code>init()</code> method that can be called after construction-time, so that I don't have to use initializers at all. (This is one of those cases where I've gotten spoiled by Java's <code>final</code> keyword + flexibility with constructors.)</p>