M
meyousikmann
The following code just sets up and fills a dynamic array of integers.
#include <cstdlib>
int main()
{
int* intArray = NULL;
int count;
count = 20;
intArray = new int[count];
for(int i=1; i <= count; i++)
intArray = i;
delete [] intArray;
}
Now, notice the last line "delete [] intArray". If I leave that line in, I
get a program error window when I run it that says:
****************************************
Debug Error!
Program: [program location and name]
DAMAGE: after Normal block (#41) at 0x00431C00
(Press Retry to debug the application)
****************************************
I don't understand why simply de-allocating the memory created by the
earlier new statement should cause a problem. Am I not supposed to delete
what I new'd? If I comment out the "delete...." line, the program runs to
completion perfectly. Can anyone shed some light on this one? I am using
MSVC++ 6.0. Any help would be greatly appreciated.
#include <cstdlib>
int main()
{
int* intArray = NULL;
int count;
count = 20;
intArray = new int[count];
for(int i=1; i <= count; i++)
intArray = i;
delete [] intArray;
}
Now, notice the last line "delete [] intArray". If I leave that line in, I
get a program error window when I run it that says:
****************************************
Debug Error!
Program: [program location and name]
DAMAGE: after Normal block (#41) at 0x00431C00
(Press Retry to debug the application)
****************************************
I don't understand why simply de-allocating the memory created by the
earlier new statement should cause a problem. Am I not supposed to delete
what I new'd? If I comment out the "delete...." line, the program runs to
completion perfectly. Can anyone shed some light on this one? I am using
MSVC++ 6.0. Any help would be greatly appreciated.