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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3dbb4bb0201c39eb X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Destructor question Date: 1998/12/06 Message-ID: #1/1 X-Deja-AN: 419244952 Sender: matt@mheaney.ni.net References: <3665B85D.A2663591@nowhere.com> NNTP-Posting-Date: Sun, 06 Dec 1998 03:36:17 PDT Newsgroups: comp.lang.ada Date: 1998-12-06T00:00:00+00:00 List-Id: Rusnak writes: > How are destrcutor methords properly implemented in Ada on tagged > records? I have the following setup: > > Given a tagged record type: > > type Instance is abstract tagged > record > ... > end record; > > type Object is access all Instance; > > type Class_Object is access all Instance'Class; > > and a package which keeps a container of "Class_Object"s. > > At the end of the day, I need to deallocate all the objects in the > container. Hers's an idea: generic type Item_Type is tagged private; package Containers is type Container_Type is limited private; procedure Add (Item : in Item_Type'Class; To : in out Container_Type); ... private type Item_List is ; type Container_Type is new Ada.Finalization.Controlled with record Items : Item_List; end record; procedure Finalize (Container : in out Container_Type); end Containers; package body Containers is procedure Finalize (Container : in out Container_Type) is begin end; ... end Containers;