|
From: Alan T. <ala...@3n...> - 2001-01-13 01:03:55
|
Dee,
I know that I should use exceptions. I am learning C++ on a =
part-time basis (by trying some programming] and have not gotten to that =
yet. I will in time. Someone else on the list gave me the new syntax =
I was using. Now I know why I was confused.
I think my original intent may have been lost in the past =
responses to my unclear inquiry. The situation I have is that I do not =
know the size of the array of a structure (an integer and several =
strings constitute one entry) I am reading from a file. Right now I =
read the file just to count the entries and then I declare the array, =
once I know its size. I wanted to be able to add another element of the =
array as I go. I also keep the entries in the order in which I read =
them, and I use another array to point to them in sorted order.
Should I even be using arrays? If so, is what I described a =
"dynamic array" (expanding the size of the array as needed)? Does =
size_of_entry mean I have to declare some maximum size? If so, what am =
I saving by using new --- stack vs. heap space?
=
Thanks, Alan (newbie)
Date: Fri, 12 Jan 2001 16:55:57 +0200 (EET)
From: Dee Zsombor <zs...@br...>
Subject: Re: [Dev-C++] dynamic array
> entry_var new int[size_of_entry];=20
> if(!entry_var)
> {
> cout << "Unable to allocate memory!";
> getch();
> exit(-1);
> }
>=20
> delete(entry_var);
There are several problems with your code, firstly the syntax of line
containing the new operator is wrong, correctly it would bee =20
int *entry_var =3D new int[size_of_entry];=20
=20
|