Article View: comp.std.c++
Article #191Re: Which delete operator should be called?
From: Pete Becker
Date: Thu, 03 Sep 1992 18:22
Date: Thu, 03 Sep 1992 18:22
39 lines
1849 bytes
1849 bytes
In article <BRENNAN.92Sep3095303@yosemite.hal.com> brennan@hal.com (Dave Brennan) writes:
>I didn't have my copy of ARM handy when I posted, and I see that it also
>says is 12.4 (p. 278) "When invoked by the delete operator, memory is freed
>by the destructor for the most derived class of the object using an
>operator delete ()."
>
>What it doesn't say is which operator delete. This tends to imply that the
>operator delete of the most derived class should be used, but as my
>previous post showed it is only used when the class being deleted has a
>virtual destructor. This quote implies that the operator delete of the
>most derived class will be called when any object is deleted?
>
>Cany anyone clarify this?
>
Don't make this problem harder than it really is. Destructors and
operator delete aren't magic. Just rephrase the question in terms of normal
functions:
class Base
{
public:
static void operation();
void f() { operation(); }
virtual void g() { operation(); }
};
class Derived : public Base
{
public:
static void operation();
void f() { operation(); }
virtual void g() { operation(); }
};
Base *bp = new Derived;
bp->f(); // invokes Base::f(), which calls Base::operation()
bp->g(); // invokes Derived::g(), which calls
// Derived::operation()
Technical Details
Message-ID:
<1992Sep3.182246.8291@genghis.borland.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!decwrl!borland.com!peteReferences:
<BRENNAN.92Sep3010854@yosemite.hal.com> <BRENNAN.92Sep3095303@yosemite.hal.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!gumby!wupost!decwrl!borland.com!pete From: pete@genghis.borland.com (Pete Becker) Subject: Re: Which delete operator should be called? Message-ID: <1992Sep3.182246.8291@genghis.borland.com> Originator: pete@genghis.borland.com Sender: news@borland.com (News Admin) Organization: Borland International References: <BRENNAN.92Sep3010854@yosemite.hal.com> <BRENNAN.92Sep3095303@yosemite.hal.com> Date: Thu, 3 Sep 1992 18:22:46 GMT Lines: 40