So, to answer your former question, you're mistaking
a pointer to an array of ints with
a pointer to an array of pointer-to-ints. The first being an array of integers, and the second being an array of pointer-to-ints; where each element of the array is a pointer that you can allocate and de-allocate with new/delete.
You're trying to deallocate the address of an integer when you do:
1 2 3
|
for(int i = 0; i < 5; i++){
deallocate(&p[i]);
}
|
As
p[i]
is an integer and
&p[i]
is the address of an integer. Delete only works on pointers, not addresses of integers.
What you want is an array of pointer-to-ints, where each element of the array can be allocated and deallocated with new.
I'm unsure if a construct like this exists; but you may be better off (at that point) just doing a vector of pointer-to-ints:
std::vector<int*> vectorOfPointerToInts;
Then you could use
delete vectorOfPointerToInts[i];
as each element in the vector would be a pointer that you could allocate and deallocate.
Make sense?
EDIT: To be clear, a construct like that DOES exist (as I believe this is how a two-dimentional array is implemented), but I'm unsure of the syntax for declaring a pointer to an array of pointer-to-ints.