Article View: hepnet.lang.c++
Article #3Re: dynamicaly allocating a two dim. array
From: Derick J.R. Qua-Gonzalez
Date: Wed, 11 Oct 1995 16:33
Date: Wed, 11 Oct 1995 16:33
48 lines
1772 bytes
1772 bytes
btrojano@chat.carleton.ca (Bart Trojanowski) writes:
>I desperately need help. My assignment is due very soon.
This shouldn't be in c.l.c. But since you xposted to C++ as wel...
>What I need to do is allocate memory for the following....
> float array[x][y];
>but dinamicaly, ie the user specifies how large it must be.
>float = **array;
|
|
WHAT?
I think you mean ``float **array;''
>*array = new (float*) [x];
|
+---- OH OH!
array = new (float*)[x];
>for (a=0;a<x;x++)
> array[a] = new float [y];
>for (a=0;a<x;x++)
> delete array[a];
>delete *array;
Since each of array[a] are themselves arrays, this line should read:
delete[] array[a];
and further:
delete[] array;
// DQG.
--
+------------------------------------------------------------------------+
| Derick R. Qua-Gonzalez | ________ |
| Department of Physics, California State University | \ / |
| dqua@EarthLink.Net | \ / |
| ``It is better to be hated for what one is, | \ / |
| than loved for what one is not.'' (A. Gide) | 32 \/ USA|
+-------------------------------------------------------------+----------+
Technical Details
Message-ID:
<dqua.813429186@dqua>Path:
arc1-ca.pugleaf.net!nntp.earthlink.net!dqua!dquaReferences:
<DG7ExA.3CG@cunews.carleton.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!nntp.earthlink.net!dqua!dqua From: dqua@earthlink.net (Derick J.R. Qua-Gonzalez) Newsgroups: hepnet.lang.c++,comp.lang.c,comp.lang.c++,cern.c++ Subject: Re: dynamicaly allocating a two dim. array Date: 11 Oct 95 16:33:06 GMT Organization: Earthlink Network, Inc. Message-ID: <dqua.813429186@dqua> References: <DG7ExA.3CG@cunews.carleton.ca> NNTP-Posting-Host: dqua.earthlink.net Followups-To: hepnet.lang.c++,comp.lang.c++,cern.c++