class temp;
temp *t;
void foo() { temp foo2; t[1] = foo2; }
int main() {
t = new temp[100];
foo();
//t[1] is still in memory?
}
- If i want an array of classes like this, am i going to have to use
pointer to pointer? (and use ‘new’
on each element in the array) E.G:
temp **t; - if i want to make an
array of 100 ptr to ptr i have todo
temp **t = new temp[100][1];is
there a better way to do that without
4 square brackets?
The code:
constructs an array 100 objects of type temp. A safer way to do the same thing is:
which absolves you of ever having to call delete[] on the array.