Mail Archives: djgpp/1997/03/29/10:44:19
Hilaire Fernandes wrote:
>
> > > Q1) delete(s); EQUAL TO delete(f) ??
> >
> > If they point to the same object (which they do here), yes.
>
> Even If I do :
> void *p;
> p=(void *)s;
> delete(p) EQUAL TO delete(s) ??
>
> So delete doesn't need to know the type of pointer to free memory !
> Great!
reminder: comp.os.msdos.djgpp is for djgpp ... "newbie questions about
C++" belong somewhere else. in fact, you should probably read the C++
faq first.
that said, the preceding is WRONG. here is what Stroustrup says in "The
C++ Programming Language" 2nd ed, p.409:
r.5.3.4 Delete
The delete operator destroys an object created by the new operator.
...
The operand of delete must be a pointer returned by new. The effect of
applying delete to a pointer not obtained from the new operator without
a placement specification is undefined and usually harmful.
>
> Another question :
> Do delete call the destructor when is argument is a pointer to a class ?
>
from the next page (500) in the same book:
The delete operator will invoke the destructor (if any, see r.12.4) for
the object pointed to.
some recommendations (based on what has worked for me):
-- get some sort of a reliable reference work.
-- try mundane programs until you get them _exactly_ right (not just
working.)
-- when you have a C or C++ question which you think is interesting
enough, try comp.lang.c.moderated or comp.lang.c++.moderated,
respectively. the answers you receive will be probably be more accurate
than here, and if your post is rejected, that will also tell you
something.
-- Sinan
*******************************************************************
A. Sinan Unur WWWWWW
|--O+O
mailto:sinan DOT unur AT cornell DOT edu C ^
http://www.people.cornell.edu/pages/asu1/ \ ~/
*******************************************************************
- Raw text -