Thread View: comp.std.c++
3 messages
3 total messages
Started by David Sachs
Thu, 07 Mar 1996 23:22
delete or delete[] ???
Author: David Sachs
Date: Thu, 07 Mar 1996 23:22
Date: Thu, 07 Mar 1996 23:22
25 lines
1732 bytes
1732 bytes
Should delete or delete[] be used for a pointer to an array type?
// It is assumed that some_type is an existing type
typedef some_type array_type[10];
array_type* a1 = new array_type[5];
array_type* b1 = new some_type[5][10];
array_type* a2 = new array_type;
array_type* b2 = new some_type[10];
...
delete[] a1;
delete[] b1;
delete a2; // or should it be delete[] a2;
delete[] b2; // or should it be delete b2;
--
***** Listen Americans, the IRS is your taxer, the IRS is one. *****
David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510
Voice: 1 708 840 3942 Deparment Fax: 1 708 840 3785
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Re: delete or delete[] ???
Author: Fergus Henderson
Date: Sat, 09 Mar 1996 05:55
Date: Sat, 09 Mar 1996 05:55
37 lines
1854 bytes
1854 bytes
b91926@fsgi01.fnal.gov (David Sachs) writes: >Should delete or delete[] be used for a pointer to an array type? `delete[]' should be used. See 5.3.5[expr.delete]/2, which says (amoung other things) that the syntax of the delete expression must match the *type* of the corresponding new expression, not its *syntax*. >// It is assumed that some_type is an existing type >typedef some_type array_type[10]; > >array_type* a1 = new array_type[5]; >array_type* b1 = new some_type[5][10]; >array_type* a2 = new array_type; >array_type* b2 = new some_type[10]; >... >delete[] a1; >delete[] b1; >delete a2; // or should it be delete[] a2; Yes, it should be `delete[] a2;'. >delete[] b2; // or should it be delete b2; Nope, that one is correct. -- Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3 --- [ comp.std.c++ is moderated. To submit articles: try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ] [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ] [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Re: delete or delete[] ???
Author: Perry Michael James
Date: Mon, 11 Mar 1996 00:32
Date: Mon, 11 Mar 1996 00:32
23 lines
1562 bytes
1562 bytes
b91926@fsgi01.fnal.gov (David Sachs) writes:
>Should delete or delete[] be used for a pointer to an array type?
>// It is assumed that some_type is an existing type
>typedef some_type array_type[10];
You need to use delete [] variable when the variable type is an array of
any kind.
--
// "C makes it easy to shoot yourself in the foot. C++ makes it
// harder, but when you do, it blows away your whole leg."
//
// -- Bjarne Stroustrup on C++
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads