access violation with delete

This is a discussion on access violation with delete within the C++ Programming forums, part of the General Programming Boards category; I am getting an access violation when I try to delete the temp object. It only get the error on ...

access violation with delete

I am getting an access violation when I try to delete the temp object. It only get the error on the third iteration of the outermost loop. I don't understand why I am getting the error because the object is declared at the beginning of the loop and destroyed at the end. Any ideas where the problem could be? Another thing, the problem compiles and runs fine with g++ but not with borland c++.

Just in general? Writing past the end of an array will do it, and its an easy error when doing a lot of math to find an array index.

If you use your IDE's debugger, you should be able to step through your function line by line, which will show you where the problem is. That might point to a math error where an array index is off by 1 or some such.

On that subject, you might want to replace some of the numeric literals in your function with constants. I notice that you keep using 30 and 29, but by using a constant, you make it much more explicit when you need 30-1, and its simple offsets like that which screw me up when working with arrays.

Start small and work up. Create the function with the minimum possible features, then compile and debug. Gradually add code, compiling and debugging at each step. I guarantee it will save you time in the development process.