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;
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;
bar = (foo *)new int[x];
for (int i=0;i<x;i++) {
bar[i] = foo(y,z);
}