<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>

Simply declaring
```
```
Object array_of_objects[10];
```
```
in C++ creates 10 default-constructed objects of type Object on the stack.
If you want to use a non-default constructor, that's not so easy in C++.  There might be a way with placement new but I couldn't tell you off the top of my head.
EDIT: Link to other question on StackOverflow
How to use placement new for the array is explained in the answer to
this question
here on StackOverflow.