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 11:34:35 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: virtual destructors - doesn't seem to work Date: 22 Apr 2003 18:32:46 +0100 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1051036474 19175 62.49.19.209 (22 Apr 2003 18:34:34 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Tue, 22 Apr 2003 18:34:34 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: archiver1.google.com comp.lang.ada:36361 Date: 2003-04-22T18:32:46+01:00 List-Id: "kat-Zygfryd" <6667@wp.pl> writes: > It doesn't seem to work :( > Look: > > -- errata to previous code > type CBase is access all Base'Class; > type CDerived is access all Derived'Class; > -- /errata > > procedure Dispose(self: in out CBase) is > begin > Put_Line("CBase.Dispose"); > end Dispose; > > procedure Dispose(self: in out CDerived) is > begin > Put_Line("CDerived.Dispose"); > end Dispose; > > function create_derived return CDerived is > begin > return new Derived; > end create_derived; > > declare > B: CBase := CBase(create_derived); > begin > Dispose(B); -- outputs "CBase.Dispose" > end; > > what am I doing wrong? Your Dispose operations aren't dispatching operations (they take a parameter of a type which you have declared, not an anonymous access-to-tagged-type). So when you say Dispose(B); it is Dispose(self: in out CBase) that gets called. type T is tagged private; type T_P is access T; type T_C is access T'Class; procedure P1 (P : T); -- dispatches procedure P2 (P : access T); -- dispatches procedure P3 (P : T_P); -- doesn't dispatch procedure P4 (P : T_C); -- doesn't dispatch I'm a bit puzzled by what you're trying to do. I would have expected your procedure Dispose(self: in out CDerived) to need to call your procedure Dispose(self: in out CBase) (because a Derived is a Base and the Base part will need finalizing). I would have thought what you'd really like to do is have just the one classwide pointer type CBase and have the correct finalization called. Matt has shown how to do that .. having two classwide pointer types seems likely to cause trouble.