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,46474020a5b291b7 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news2.google.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.freenet.de!newsfeed01.chello.at!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Free'ing dynamic abstract tagged types.. Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1158872883.994303.80430@b28g2000cwb.googlegroups.com> Date: Fri, 22 Sep 2006 09:21:29 +0200 Message-ID: NNTP-Posting-Date: 22 Sep 2006 09:21:25 CEST NNTP-Posting-Host: fa4db13e.newsspool4.arcor-online.net X-Trace: DXC=]o`OjdnG4hO@Y=h<_c3PkH4IUK\BH3YB1h@;:3QP9_BDNcfSJ;bb[EFCTGGVUmh?DN\HXHJ4e80N7PnhKJEAESO X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6694 Date: 2006-09-22T09:21:25+02:00 List-Id: On 21 Sep 2006 14:08:04 -0700, ldb wrote: > Ok, so I have this abstract tagged type called Person (for the sake of > discussion), and I have an Access_Person (which is access all > people'class). > > I have some derived types, like Man and Child, with their own added > fields. And I have defined Access_Man, Access_Child, as normal accesses > to these types. That usually were a bad idea, because it creates a parallel types hierarchy: Person <-- Man Specific_Access_Person <-- Specific_Access_Man Maintaining both is an unnecessary burden. Note that you can allocate Man having Access_Person as the target. Usual pattern is: Man_Ptr : Access_Person := new Man; -- OK, we want to access some fields of Man after having -- created it, so: declare Object : Man'Class renames Man'Class (Man_Ptr.all); begin -- Do with Object what you have to with Man. Object -- is not new, it is a Man'Class view of the thing pointed -- by Man_Ptr. ... end; > I want to free an Access_Person that was dynamically allocated. > ap : Access_Person; > begin > ap := Access_Person(new Man); > free(ap); > ... Others have answered this. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de