title: How do you call a constructor for global objects, for arrays of objects, and for objects inside classes/structs?
body: <p>How would you call the constructor of the following class in these three situations: Global objects, arrays of objects, and objects contained in another class/struct?</p>
  
  <p>The class with the constructor (used in all three examples):</p>
  
  <pre><code>class Foo {
      public:
          Foo(int a) { b = a; }
  
      private:
          int b;
  };
  </code></pre>
  
  <p>And here are my attempts at calling this constructor:</p>
  
  <h2>Global objects</h2>
  
  <pre><code>Foo global_foo(3); // works, but I can't control when the constructor is called.
  
  int main() {
      // ...
  }
  </code></pre>
  
  <h2>Arrays of objects</h2>
  
  <pre><code>int main() {
      // Array on stack
      Foo array_of_foos[30](3); // doesn't work
  
      // Array on heap
      Foo *pointer_to_another_array = new Foo(3) [30]; // doesn't work
  }
  </code></pre>
  
  <p>There I'm attempting to call the constructor for all elements of the arrays, but I'd also like to know how to call it on individual elements.</p>
  
  <h2>Objects contained in classes/structs</h2>
  
  <pre><code>class Bar {
      Foo foo(3); // doesn't work
  };
  
  int main() {
      Bar bar;
  }
  </code></pre>