Dynamically allocated arrays

I'm writing a program for a class and I'm stuck trying to figure out how to implement the following function


private members:
stack<T*> pointers
Everytime we allocate a new array, we put a pointer to it on this stack
When the destructor is called, all the pointers in this stack are deleted.


I don't exactly know how to even start this. I imagine that the each node on the stack will have an array?
Each node on the stack has a pointer.

1
2
3
4
int * p = new int [3];
// p is a pointer
// p has the address of a memory block that is large enough for 3 int
p[1] = 7; // Dereferencing pointer gives access to an element in the array 
I guess what I actually needed for this program was to simply write
 
pointers.push();


and call that whenever I need to create an array.
Thanks anyways keskiverto
Topic archived. No new replies allowed.