home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,880 of 33,346   
   goran.pusic@googlemail.com to alexo   
   Re: fails to call destructor in a linked   
   01 Mar 13 09:52:52   
   
   { Reformatted; please remove double-spacing in the quoting. -mod }   
      
   On Thursday, February 28, 2013 8:55:05 AM UTC+1, alexo wrote:   
   > { Reformatted; please limit your lines to 70 characters -mod }   
   >   
   > > At the end of main head goes out of scope, head is a Node*, and   
   > > pointers have trivial destructors. If you want the list to be   
   > > destroyed, you can do one of the following:   
   > >   
   > > explicitly delete head to make the list go away.   
   >   
   > done.   
   >   
   > and it correctly called the Node destructor for each element of the   
   > list, without having to cross the list and delete Nodes   
   > individually. As Ian Collins suggested me to do.   
   > I thought I made some error in building the list.   
   >   
   > I didn't explicitly called delete on head because I thought head going   
   > out of scope, the delete operator would have been called   
   > automatically.   
      
   Why did you think that? There is NO documentation that would claim such a   
   thing, and there are LOADS of documentation that would say "if you do a new,   
   you must do a delete (eventually, somewhere, only once ;-)).   
      
   Word of advice: always ask yourself "what would I need to do had it been plain   
   C here?" In this case, C equivalents are e.g. malloc and free. Called malloc?   
   Must call free!   
      
   G.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca