From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: newbie questions about C++ Date: Sat, 29 Mar 1997 01:30:37 -0500 Organization: Cornell University http://www.cornell.edu Lines: 57 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <333CB70D.E84@cornell.edu> References: <333BE16F DOT 7C80 AT ms11 DOT hinet DOT net> <333C0AE3 DOT 5530AE41 AT alcyone DOT com> <333CA827 DOT 1545 AT ms11 DOT hinet DOT net> Reply-To: asu1 AT cornell DOT edu NNTP-Posting-Host: cu-dialup-0095.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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/ \ ~/ *******************************************************************