From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,de1c23707584fc3c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-04-22 10:33:58 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: virtual destructors Date: 22 Apr 2003 10:33:57 -0700 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0304220933.11d578f@posting.google.com> References: NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1051032838 7239 127.0.0.1 (22 Apr 2003 17:33:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 22 Apr 2003 17:33:58 GMT Xref: archiver1.google.com comp.lang.ada:36358 Date: 2003-04-22T17:33:58+00:00 List-Id: "kat-Zygfryd" <6667@wp.pl> wrote in message news:... > > 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;