0

the following example shows the problem:

"int* pointername = new int"
followed by "delete pointername" - no problem.

however:
"int* pointername = new int[8]" followed by "delete pointername"
flags`an error during execution. (compile/built are passing ok).

This happens with 2 very different compilers: vc++ (native) and djgpp one.
looks like I am missing some thing in c++ in general.

I selected type *int but it coulds be any pointer type(pointer to a class for example).

Thanks for your attention
Uri.

3
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by uw1
0

Should work fine. The error is probably the result of something else in the code.

Can you post a small example of code that crashes?

1

You must delete array pointer by delete [] pointer operator.
In other words a pointer obtained from new[] must be deleted by delete [] .

Learn C++ more carefully ;) ...

Votes + Comments
Thanks for the correction
0

In other words a pointer obtained from new[] must be deleted by delete [] .

Damn I totally missed the missing brackets..

Learn C++ more carefully .

I'll do that, thanks for the advice ;)

0

Thanks ArkM,niek_e for the solution.:)
uw1.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.