Re: new/delete
- From: "John Bode" <john_bode@xxxxxxxxxxx>
- Date: 30 Jun 2006 08:19:40 -0700
c language wrote:
Hi,
I am using pointer in my program. I write them like:
*DIST=new int [M+1];
and when I want to make the memory free, I write:
delete DIST;
before the "return 0".
I don't know if the way that I am doing is correct or not because I
have some segmentation fault (core dumped) error.
Any suggestions?
Thanks,
Mohsen
First, new and delete are C++ operators, not C. You might want to ask
this in comp.lang.c++.
Second, it would help if you could post a small but *complete* program
that demonstrates the problem, otherwise you aren't going to get a lot
of help. From what you've posted here, I *think* your problem is that
you're dereferencing DIST when you shouldn't be; replace your
allocation above with
DIST = new int [M+1]; // note that I've removed the * operator
but you haven't given enough information for me to be sure.
.
- References:
- new/delete
- From: c language
- new/delete
- Prev by Date: same name global variable multi-files
- Next by Date: Re: new/delete
- Previous by thread: Re: new/delete
- Next by thread: Re: new/delete
- Index(es):
Relevant Pages
|