I want to make a dynamic array of foo, with the number of items being x. Arguments y and z are to be passed to the constructor of the item foo. I was hoping to do something similar to:
Foo* bar = new Foo(y, z)[x];
However that produced the following compiler error:
error: expected `;' before '[' token
So after speaking with an experienced friend, he gave me this, which he admitted was a lazy way of doing it, but it works. I was wondering, is there a better/proper way?
Foo* bar = (Foo*) new int[x];
for (int i = 0; i < x; i++) {
bar[i] = Foo(y, z);
}