"Artie Gold" <ar*******@austin.rr.com> wrote in
message news:39*************@individual.net...
Sowen wrote: hi,
Hi.
I have the following code
object obj_1;
object obj_2;
object obj_3;
object *objs[] = { &obj_1, &obj_2, &obj_3 };
do I need to delete the "objs"? I tried different way, they were all wrong.
if I don't need to delete it, why?
.... If you haven't `new'-ed it you don't `delete' it.
Mr. Gold's rule is worth remembering (and observing),
but here is the why: The objects named obj_? are
constructed automatically, either as the block in which
they are defined is entered, or when the program begins
if there is no such block. The compiler arranges for
their destructors to be run automatically also, either
when the block is exited or the program exits. So
you do not need to worry about it.
Another point, (expanding on that rule): The memory
occupied by those objects is allocated by the compiler
(or the linker or OS, if you crave pedanticism) and is
also deallocated by the same actor. The only time
the programmer is responsible for deallocation is
when the allocation has not been done automatically.
In short, every execution of a delete should map to
a preceding execution of a new, (at least until you
get into exotic C++ techniques involving placement
new, which you can put off learning for a good while.)
--
--Larry Brasfield
email:
do***********************@hotmail.com
Above views may belong only to me.