home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13246 < prev    next >
Encoding:
Text File  |  1992-09-02  |  1.3 KB  |  61 lines

  1. Path: sparky!uunet!olivea!hal.com!hal!brennan
  2. From: brennan@hal.com (Dave Brennan)
  3. Newsgroups: comp.lang.c++
  4. Subject: cfront, objectcenter bug?
  5. Message-ID: <BRENNAN.92Sep3003646@yosemite.hal.com>
  6. Date: 3 Sep 92 06:36:46 GMT
  7. Organization: HaL Computer Systems, Austin, TX
  8. Lines: 50
  9. NNTP-Posting-Host: yosemite.hal.com
  10.  
  11. When the following program is run, both cfront and objectcenter print:
  12.  
  13. destruct derived
  14. destruct base
  15. destruct base
  16. delete base
  17.  
  18. g++ won't compile this program.  I believe that the explicit call to
  19. base::~base should not result in the derived destructor being called.
  20. Can anyone confirm or deny this?
  21.  
  22.  
  23. extern "C" void puts (char *);
  24.  
  25. class base
  26. {
  27. public:
  28.   virtual ~base ()
  29.     { puts ("destruct base"); }
  30.   void operator delete (void *)
  31.     { puts ("delete base"); }
  32.   void destruct ()
  33.     { base::~base (); }
  34. };
  35.  
  36. class derived : public base
  37. {
  38. public:
  39.   ~derived ()
  40.     { puts ("destruct derived"); }
  41.   void operator delete (void *)
  42.     { puts ("delete derived"); }
  43. };
  44.  
  45. int
  46. main ()
  47. {
  48.   base *b = new derived;
  49.  
  50.   // This call to destruct wipes out the vtbl!
  51.   b->destruct ();
  52.  
  53.   delete b;
  54. }
  55.  
  56. --
  57. Dave Brennan                                      HaL Computer Systems
  58. brennan@hal.com                                         (512) 794-2855
  59.  
  60. Visit the Emacs Lisp Archive: archive.cis.ohio-state.edu:pub/gnu/emacs
  61.