title: C++: how to create an array of objects on the stack?
body: <p>Consider the following piece of Java code.</p>
  
  <pre><code>int N = 10;
  Object obj[] = new Object[N];
  for (int i = 0; i &lt; N; i++) {
      int capacity = 1000 * i;
      obj[i] = new ArrayList(capacity);
  }
  </code></pre>
  
  <p>Because in Java, all objects live on the Heap, the array does not
  contain the objects themselves, but references to the objects. Also,
  the array itself is also an object, thus it lives on the heap.</p>
  
  <p>What is the equivalent in C++, but keeping the array and objects on
  the stack, to avoid as much as possible needing new and delete ?</p>
  
  <p>Edit: changed the code to use a custom constructor.</p>