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,2cd78c85026e128 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Help on arrays of tagged types Date: 1998/01/13 Message-ID: #1/1 X-Deja-AN: 315730866 Content-Transfer-Encoding: 8bit References: <34B37A65.607798A2@catalina-inter.net> <34BC054C.5DB2@peak.org> Content-Type: text/plain; charset=ISO-8859-1 Organization: Estormza Software Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-01-13T00:00:00+00:00 List-Id: In article <34BC054C.5DB2@peak.org>, jamesjb@peak.org wrote: >Hello. This problem is quite similar to one I have been having also. >I am trying to create a linked list type for objects derived from a >root tagged type. > >The goal is to have a homogenous Linked_List object, that stores objects >of a tagged type derived from "Root_Data". So you could set up as >follows: > > Socket_List : Linked_List; > Descriptor_List : Linked_List; > etc. > >The list is set up analogously to the example below, but the problem >arises >when I try to access the elements of the list. I think the problem is >that >I try to convert from "access Root_Data'Class" to "access from Root_Data>", >which cannot work because it would entail extending the structure of the >object to the >derived type. > >> >> type Root_Data_Class_Access_All is access all Root_Data'Class; >> >> type Root_Data_Array is >> array (Positive range <>) of Root_Data_Class_Access_All; You want a "typeless" data structure. You'll have to downcast in that case: declare Descriptor_As_Data : Root_Data'Class renames Heading (Descriptor_List).all; File : File_Descriptor renames File_Descriptor (Descriptor_As_Data); begin It's perfectly legal to downcast a class-wide object into the type you want, because there'll be a tag check to make sure the object really is (or is descended from) File_Descriptor. That being said, yes, you really do want to use a generic, if the data structure is homogeneous. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271