Author: Bruce Moreland
Date: 09:44:34 06/10/00
Go up one level in this thread
On June 10, 2000 at 03:10:55, James Robertson wrote: >I just thought of something new: will everything be ok if I write: > >int *a = new char[256]; >int *b = a; >a = new char[256]; >delete [] b; >delete [] a; > >? > >Based on the previous answers I am guessing this will work. Is there any problem >with it? > >James Yes, this will work. When you allocate something you get the address of it. You can delete the object at that address, once, and you are doing that. The name of the thing doesn't have much to do with the thing. That's sort of the point of run-time allocated memory. When you allocate something from the heap, you get into trouble if you: 1) Delete it more than once. 2) Access it after you delete it. 3) Forget to delete it. These are all common bugs. bruce
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.