home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / std / cplus / 1127 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!gumby!wupost!decwrl!borland.com!pete
  3. From: pete@genghis.borland.com (Pete Becker)
  4. Subject: Re: Which delete operator should be called?
  5. Message-ID: <1992Sep3.182246.8291@genghis.borland.com>
  6. Originator: pete@genghis.borland.com
  7. Sender: news@borland.com (News Admin)
  8. Organization: Borland International
  9. References: <BRENNAN.92Sep3010854@yosemite.hal.com> <BRENNAN.92Sep3095303@yosemite.hal.com>
  10. Date: Thu, 3 Sep 1992 18:22:46 GMT
  11. Lines: 40
  12.  
  13. In article <BRENNAN.92Sep3095303@yosemite.hal.com> brennan@hal.com (Dave Brennan) writes:
  14. >I didn't have my copy of ARM handy when I posted, and I see that it also
  15. >says is 12.4 (p. 278) "When invoked by the delete operator, memory is freed
  16. >by the destructor for the most derived class of the object using an
  17. >operator delete ()."
  18. >
  19. >What it doesn't say is which operator delete.  This tends to imply that the
  20. >operator delete of the most derived class should be used, but as my
  21. >previous post showed it is only used when the class being deleted has a
  22. >virtual destructor.  This quote implies that the operator delete of the
  23. >most derived class will be called when any object is deleted?
  24. >
  25. >Cany anyone clarify this?
  26. >
  27.  
  28.     Don't make this problem harder than it really is.  Destructors and
  29. operator delete aren't magic.  Just rephrase the question in terms of normal
  30. functions:
  31.  
  32.     class Base
  33.     {
  34.     public:
  35.         static void operation();
  36.         void f() { operation(); }
  37.         virtual void g() { operation(); }
  38.     };
  39.  
  40.     class Derived : public Base
  41.     {
  42.     public:
  43.         static void operation();
  44.         void f() { operation(); }
  45.         virtual void g() { operation(); }
  46.     };
  47.  
  48.     Base *bp = new Derived;
  49.     bp->f();    // invokes Base::f(), which calls Base::operation()
  50.     bp->g();    // invokes Derived::g(), which calls 
  51.             // Derived::operation()
  52.  
  53.