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

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!news.mentorg.com!sdl!adk
  3. From: adk@Warren.MENTORG.COM (Ajay Kamdar)
  4. Subject: Re: Which delete operator should be called?
  5. Message-ID: <1992Sep3.171147.3362@Warren.MENTORG.COM>
  6. Organization: Mentor Graphics Corp. - IC Group
  7. References: <BRENNAN.92Sep3010854@yosemite.hal.com>
  8. Date: Thu, 3 Sep 1992 17:11:47 GMT
  9. Lines: 57
  10.  
  11. In article <BRENNAN.92Sep3010854@yosemite.hal.com> brennan@hal.com (Dave Brennan) writes:
  12.  
  13. >Somewhat related to this, I need to be able to call the virtual destructor
  14. >of an object without deleting it.  I can't get any compilers to accept any
  15. >destructor calling syntax other than "class::~class()" (where "class" is a
  16. >class name).  In cfront this syntax DOES call the virtual destructor (ie:
  17. >if I call "base::~base()" from a base method, the derived destructor is
  18. >called).  Lucid CC it only called the base class destructor, which seems
  19. >like the correct behavior.  g++ 2.2.2 wouldn't accept any kind of explicit
  20. >calls to a destructor.  Can anyone tell me how to call a virtual destructor
  21. >in a way that least cfront 2.1 will accept and is correct C++?
  22. >
  23.  
  24. #include <iostream.h>
  25.  
  26. class A {
  27. public:
  28.         A() {}
  29.         virtual ~A() {cout << "A's dtor" << endl;}
  30.  
  31.         virtual void callDtorInPlace() {this->A::~A();}
  32.            // legal code. Will work in both 2.1 and 3.0
  33.  
  34. //      virtual void callDtorInPlace() {this->~A();}
  35.            // legal code, but doesn't work in 2.1.
  36.            // Works ok in 3.0
  37.  
  38. //      virtual void callDtorInPlace() {A::~A();}
  39.                 // This is illegal, but works under 2.1.
  40.                 // 3.0 compiles this, but doesn't produce any output.
  41. };
  42.  
  43. class B : public A {
  44. public:
  45.         B() {}
  46.         ~B() {cout << "B's dtor" << endl;}
  47.  
  48.         void callDtorInPlace() {this->B::~B();}
  49.            // legal code. works with both 2.1 and 3.0
  50.  
  51. //        void callDtorInPlace() {this->~B();}
  52.            // legal code which does not work with 2.1. Works ok with 3.0
  53.  
  54. //      virtual void callDtorInPlace() {B::~B();}
  55.            // illegal code which works with 2.1
  56. };
  57.  
  58. main()
  59. {
  60.         A *a = new B();
  61.         a->callDtorInPlace();
  62. }
  63. -- 
  64. I speak for none but myself.
  65.  
  66. Ajay Kamdar                               Email : ajay_kamdar@mentorg.com
  67. Mentor Graphics, IC Group (Warren, NJ)    Phone : (908) 580-0102
  68.