
Newbie Question: using delete with dynamic 2-d arrays
<yet more off-topic>
Quote:
Quote:
>> >On Thu, 22 Apr 1999 02:13:13 GMT, Chirag Mehta
>> [snip]
>> >> Is this the correct way to delete array?
>> [snip]
>> >The correct way is to ask in comp.lang.c++, not in comp.lang.c. But
>> >the correct way is to have one delete [] for each new [], and in
>> >reverse order.
>> "in reverse order"? Am I missing something here?
><further off-topic>
>If you use delete[] on an object it must have been allocated with new[],
>not with new. For example:
[snip]
What my question actually was meant to address was that
JK's post could easily be interpreted to mean that new[] and
delete[] must be matched in some sort of LIFO way, i.e.:
char *p = new char[x];
char *q = new char[y];
delete [] q;
delete [] p;
where q /has/ to be deleted before p.
While the C++ committee has created such a monstrosity that I
might have missed this little nugget about "in reverse order" re
new and delete, I think the sentence only inadvertently gives this
impression. My question was actually rhetorical, to give JK an
opportunity to clarify the sentence.
Sorry about the further off-topic posting, but enough people read
this newsgroup that the issue needed to be clarified. I believe this
is especially important when it arises from a post by someone
like JK, who is normally quite clear in his posts.
In retrospect, an ambiguous rhetorical question is not really the
best way to address a (perceived) lack of clarity in a post :)
-dave
--
------------------------------------------------------------------------
* Remember to remove the spam blocker when replying.
* Return address is: dstarr AT xnet DOT com
------------------------------------------------------------------------