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,872 of 33,346   
   alexo to All   
   Re: fails to call destructor in a linked   
   27 Feb 13 23:55:05   
   
   From: alelvb@inwind.it   
      
   { 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.  As you rightly say, I should have encapsulated head   
   into a class and then its destructor would have been called and the   
   list destroyed.  I'll try out this solution.   
      
   But pardon me the question: what is a smart pointer?   
      
   Oo Tiib suggested me to use std::unique_ptr   
   But I don't know   
   what is it and how to do it.   
      
   You are forgetting I'm a very beginner of C++   
      
   Thank you for your replies   
      
      
      
   --   
         [ 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