I have a function similar to this:
void foo(obj ary[], int arysize) {
for (int i = 0; i < arysize; i++)
ary[i] = obj(i, "abc");
}
And I call it like this:
obj array[5];
foo(array, 5);
It's supposed to populate the array with my objects. However, when it returns, the objects are garbage. It works with value types like int
and stuff, so I think it's something to do with the object I create being local in scope so it gets destroyed when the function returns. I would like to be able to do this without using dynamically allocated objects with new
. How can I do this?