Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!lupine!rfg From: rfg@NCD.COM (Ron Guilmette) Newsgroups: comp.lang.c++ Subject: Re: delete [] Keywords: delete class [] Message-ID: <985@lupine.NCD.COM> Date: 28 Jul 90 18:50:04 GMT References: <641@atcmpe.atcmp.nl> Reply-To: rfg@ncd.com Organization: Network Computing Devices, Inc., Mt. View, CA Lines: 48 In article <641@atcmpe.atcmp.nl> leo@atcmp.nl (Leo Willems) writes: >When shifting from 2.0 to 2.1 I found myself in problems with: > >func(){ > classtype *m = new classtype[10]; > > delete[10] m; >} > >In 2.0 this works fine, in 2.1 not, that compilers suggests: > > delete [] m; > >which indeed works correct. (but not in 2.0, which accepts the code but >generates a .c file with a syntax error) > >Is delete[] indeed the correct way ? This is a relative recent change in the definition of the language, and in the cfront implementation of the language. Thus, it is not surprizing that it has thrown some people for a loop. The new Annotated C++ Reference Manual (E&S) clearly indicates that the proper way to delete an array of things which are pointed to by some pointer `p' is to say: delete [] p; In the old days (e.g. when using 2.0 and earlier) you needed to write the actual number of elements inside the [], but that's not needed anymore, nor will it be in the future. >Should delete[] be accepted by 2.0 or is it new to 2.1? This is new in 2.1. You will not be able to use this simpler notation/syntax if you are still working with cfront 2.0 (or earlier). P.S. For anybody out there who is doing serious work with C++ and who has not yet obtained a copy of the new Annotated C++ Reference Manual, I have only two words for you. Get it. 'nuff said. -- // Ron Guilmette // C++ Entomologist // Internet: rfg@ncd.com uucp: ...uunet!lupine!rfg // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.