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 31,966 of 33,346   
   Ulrich Eckhardt to All   
   Re: Incomplete class with auto_ptr   
   02 Mar 12 02:38:10   
   
   464b92e4   
   From: ulrich.eckhardt@dominolaser.com   
      
   Am 29.02.2012 12:58, schrieb Kris Prad:   
   > #include   
   > class A; // fwd class decl.   
   >   
   > void test()   
   > {   
   >       A* a;   
   >       std::auto_ptr  ap(a); // A is not defined here   
   > }   
      
   For your info, all templates of the C++ standard library (not sure about   
   C++11 though) are only valid when given complete types. A   
   forward-declared class is not complete, so your code is invalid.   
      
      
   > "memory", line 76: warning: delete of pointer to incomplete class   
   >       ~auto_ptr() { delete _M_ptr; }   
   >   
   > My question:   
   > Eventually ~auto_ptr() must see the underlying class definition for   
   > the code to work correctly. So, why is this only a warning, and not a   
   > full fledged error?   
      
   As often, undefined behaviour does not require an error. It doesn't even   
   require a warning, actually. In this case, it's a warning that you   
   should take seriously though.   
      
   Uli   
      
      
   --   
         [ 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