comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: virtual destructors
Date: 22 Apr 2003 10:33:57 -0700
Date: 2003-04-22T17:33:58+00:00	[thread overview]
Message-ID: <1ec946d1.0304220933.11d578f@posting.google.com> (raw)
In-Reply-To: b83l69$7bk$1@news.onet.pl

"kat-Zygfryd" <6667@wp.pl> wrote in message news:<b83l69$7bk$1@news.onet.pl>...
>
> I want to have destructors working on access' to class wide types,
> so that when passed a variable, an actual type destructor was
> called, not a one overloaded for the specific type.
> 
> example:
> 
> type Base is tagged record ... end record;
> type PBase is access Base;
> type CBase is access Base'Class;
> 
> type Derived is new Base with record ... end record;
> type PDerived is access Derived;
> type CDerived is access Derived'Class;
> 
> procedure Free is new Ada.Unchecked_Deallocation(Base,PBase);
> procedure Free is new Ada.Unchecked_Deallocation(Derived,PDerived);
> 
> procedure Dispose(self: in out CBase) is
> begin
>    --?
>    self := null;
> end Dispose;
> 
> procedure Dispose(self: in out CDerived) is
> begin
>     -- ?
>    self := null;
> end Dispose;
> 
> declare
>     B: CBase := new Base;
>     D: CBase := new Derived;
> begin
>     Dispose(B);
>     Dispose(D);
> end;
> 
> I want both Disposes to work as they should, what should I fill them with?

Give the class a primitive operation that accepts an access parameter:

procedure Do_Dispose (B : access Base) is ...;
procedure Do_Dispose (D : access Derived) is ...;

procedure Dispose (B : in out CBase) is
begin
   if B /= null then
      Do_Dispose (B);  --dispatches
      B := null;
   end if;
end Dispose;



  parent reply	other threads:[~2003-04-22 17:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-22 14:18 virtual destructors kat-Zygfryd
2003-04-22 14:27 ` Stephen Leake
2003-04-22 14:56   ` kat-Zygfryd
2003-04-22 15:45     ` kat-Zygfryd
2003-04-22 16:34       ` tmoran
2003-04-22 21:32         ` Robert A Duff
2003-04-22 17:18       ` Stephen Leake
2003-04-22 16:34         ` Simon Wright
2003-04-22 19:57           ` Stephen Leake
2003-04-22 20:19             ` Simon Wright
2003-04-22 21:23             ` Robert A Duff
2003-04-23 15:16         ` Matthew Heaney
2003-04-22 17:31       ` virtual destructors - doesn't seem to work kat-Zygfryd
2003-04-22 17:32         ` Simon Wright
2003-04-22 17:33     ` Matthew Heaney [this message]
2003-04-22 17:28 ` virtual destructors Matthew Heaney
2003-04-22 17:40   ` kat-Zygfryd
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox