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,884 of 33,346   
   alexo to All   
   Re: fails to call destructor in a linked   
   02 Mar 13 04:11:27   
   
   From: alelvb@inwind.it   
      
   goran.pusic@googlemail.com ha scritto:   
      
   >> 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!   
      
      
   head is not allocated with new, so I didn't think to call delete on   
   it.  If I delete head the destructors are correctly called.  That was   
   my source of doubts. And I still don't understand why.   
      
      
   --   
         [ 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