Mail Archives: djgpp/1997/02/23/00:57:45
Hades wrote:
> whats the difference between delete blah and delete blah[]
> ...one book i have says to deallocate an array with delete blah
> ...another book mentions delete blah[]
>
> any help or references to places with help on this subject would
> be appreciated
You're trying to create a double-dimensioned array in one shot. You can't
do that. You're also trying to initialize an array of objects with a
non-default constructor. You also can't do that.
If you want to allocate a two-dimensional array, you need to do it in two
passes, just like in C:
char **pp = new char *[20];
for (int i = 0; i < 20; i++)
pp[i] = new char[20];
If you want to initialize it, you have to do it after the objects have been
allocated:
for (int i = 0; i < 20; i++)
for (int j = 0; j < 20; j++)
pp[i][j] = 'X';
To delete them, you should use
for (int i = 0; i < 20; i++)
delete[] pp[i];
delete[] pp;
--
Erik Max Francis, &tSftDotIotE / email: max AT alcyone DOT com
Alcyone Systems / web: http://www.alcyone.com/max/
San Jose, California, United States / icbm: 37 20 07 N 121 53 38 W
\
"I am become death, / destroyer of worlds."
/ J. Robert Oppenheimer (quoting legend)
- Raw text -