Article View: comp.std.c++
Article #190Re: Which delete operator should be called?
From: Ajay Kamdar
Date: Thu, 03 Sep 1992 17:11
Date: Thu, 03 Sep 1992 17:11
57 lines
2382 bytes
2382 bytes
In article <BRENNAN.92Sep3010854@yosemite.hal.com> brennan@hal.com (Dave Brennan) writes:
>Somewhat related to this, I need to be able to call the virtual destructor
>of an object without deleting it. I can't get any compilers to accept any
>destructor calling syntax other than "class::~class()" (where "class" is a
>class name). In cfront this syntax DOES call the virtual destructor (ie:
>if I call "base::~base()" from a base method, the derived destructor is
>called). Lucid CC it only called the base class destructor, which seems
>like the correct behavior. g++ 2.2.2 wouldn't accept any kind of explicit
>calls to a destructor. Can anyone tell me how to call a virtual destructor
>in a way that least cfront 2.1 will accept and is correct C++?
>
#include <iostream.h>
class A {
public:
A() {}
virtual ~A() {cout << "A's dtor" << endl;}
virtual void callDtorInPlace() {this->A::~A();}
// legal code. Will work in both 2.1 and 3.0
// virtual void callDtorInPlace() {this->~A();}
// legal code, but doesn't work in 2.1.
// Works ok in 3.0
// virtual void callDtorInPlace() {A::~A();}
// This is illegal, but works under 2.1.
// 3.0 compiles this, but doesn't produce any output.
};
class B : public A {
public:
B() {}
~B() {cout << "B's dtor" << endl;}
void callDtorInPlace() {this->B::~B();}
// legal code. works with both 2.1 and 3.0
// void callDtorInPlace() {this->~B();}
// legal code which does not work with 2.1. Works ok with 3.0
// virtual void callDtorInPlace() {B::~B();}
// illegal code which works with 2.1
};
main()
{
A *a = new B();
a->callDtorInPlace();
}
--
I speak for none but myself.
Ajay Kamdar Email : ajay_kamdar@mentorg.com
Mentor Graphics, IC Group (Warren, NJ) Phone : (908) 580-0102
Technical Details
Message-ID:
<1992Sep3.171147.3362@Warren.MENTORG.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!news.mentorg.com!sdl!adkReferences:
<BRENNAN.92Sep3010854@yosemite.hal.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!news.mentorg.com!sdl!adk From: adk@Warren.MENTORG.COM (Ajay Kamdar) Subject: Re: Which delete operator should be called? Message-ID: <1992Sep3.171147.3362@Warren.MENTORG.COM> Organization: Mentor Graphics Corp. - IC Group References: <BRENNAN.92Sep3010854@yosemite.hal.com> Date: Thu, 3 Sep 1992 17:11:47 GMT Lines: 57