From: jklowden@speakeasy.net   
      
   On Tue, 14 Feb 2012 17:16:59 -0800 (PST)   
   Ulrich Eckhardt wrote:   
      
   > > List(const List& otherlist):   
   > > _start(0),_finish(0),_numberofelements(0)   
   > > {   
   > > each(it,otherlist)   
   > > {   
   > > insertafter(finish(),otherlist(it));   
   > > }   
   > > }   
   >   
   > Not exception-safe. If inserting inside the ctor throws, you wont get   
   > the destructor called since the object hasn't been constructed yet.   
      
   I enjoyed the rest of your critique, and want to be sure I understand   
   this one. IIUC:   
      
   If otherlist has 4 elements (a,b,c,d), and insertafter throws on, say,   
   'c', the exception will not invoke ~List and not free the storage for   
   elements 'a' and 'b'.   
      
   I suppose the proper solution is to try, catch, delete, and throw:   
      
   try {   
    insertafter(finish(),otherlist(it));   
   } catch(...) {   
    erase(_start,_finish); // and hope   
    throw;   
   }   
      
   or use private inheritance.   
      
   --jkl   
      
      
   --   
    [ 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)   
|