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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,672558c47d86bb1d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!news.cs.univ-paris8.fr!newsfeed.vmunix.org!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Hierarchy destruction in Ada Date: Sun, 12 Dec 2004 17:52:10 +0100 Organization: None Message-ID: <1764085.COooLuJmQE@linux1.krischik.com> References: Reply-To: martin@krischik.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1102870427 00 21446 Lxy4X6yLbPT0IbM 041212 16:53:47 X-Complaints-To: usenet-abuse@t-online.de X-ID: ZYOIC8ZHwec6rnGfhMLn3Mor-T9YslwyDTvdjl4QyyYLCskdf52-EE User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:6902 Date: 2004-12-12T17:52:10+01:00 List-Id: Michael Mounteney wrote: > Ada 95 provides a mechanism with tagged and type'class to allow > dynamic dispatch. So if one has: > > procedure something (O : basetype'class) is > begin > enact (O); > end something; > > then as we all know, with the appropriate redefinitions of enact () > for the subtypes of basetype, we have dynamic dispatch. But what > about deallocation ? I want to declare: > > type handle is access all basetype; The trick is: type handle is access basetype'Class; > procedure dispose (ptr : in out handle); If you want to write a "dispose" function you should not use "access all". Reason: access all allows any kind of access but the "dispose" needs the right type of access to work properly. i.E: declare X : aliased basetype; begin dispose (X'Access); end; You don't want that, don't you? If you need the "all" features for other reasons then consider: type pool_handle is access basetype'Class; type any_handle is access all basetype'Class; > and can't see how to make this deallocate the correct object. > Obviously, one can dynamically dispatch on ptr.all but it seems > impossible to solve the complete problem without an unchecked > conversion. Anyone ? When you deallocate an "access basetype'Class" then the propper finalisation is done. With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com