Article View: comp.std.c++
Article #188Which delete operator should be called?
From: Dave Brennan
Date: Thu, 03 Sep 1992 07:08
Date: Thu, 03 Sep 1992 07:08
55 lines
2277 bytes
2277 bytes
It's not clear to me which delete operator should be called in the
following example program. The ARM says that the delete operator is
inherited, but is not virtual (which certainly makes since, because it
must be static).
All compilers that I testest this on indicated that the derived delete
operator is called when the destructor is virtual. If the destructor is
non-virtual the base class delete operator is called. So at least in some
compilers the delete operator IS virtual if the destructor is. This may be
reasonable behavior but seems contrary to what the ARM says.
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++?
extern "C" void puts (char *);
class base
{
public:
virtual ~base ()
{ puts ("destruct base"); }
void operator delete (void *)
{ puts ("delete base"); }
void destruct ()
{ base::~base (); }
};
class derived : public base
{
public:
~derived ()
{ puts ("destruct derived"); }
void operator delete (void *)
{ puts ("delete derived"); }
};
int
main ()
{
base *b = new derived;
delete b;
}
--
Dave Brennan HaL Computer Systems
brennan@hal.com (512) 794-2855
Visit the Emacs Lisp Archive: archive.cis.ohio-state.edu:pub/gnu/emacs
Technical Details
Message-ID:
<BRENNAN.92Sep3010854@yosemite.hal.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!olivea!hal.com!hal!brennanShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!hal.com!hal!brennan From: brennan@hal.com (Dave Brennan) Newsgroups: comp.std.c++ Subject: Which delete operator should be called? Message-ID: <BRENNAN.92Sep3010854@yosemite.hal.com> Date: 3 Sep 92 07:08:54 GMT Organization: HaL Computer Systems, Austin, TX Lines: 55 NNTP-Posting-Host: yosemite.hal.com