From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Help on arrays of tagged types
Date: 1998/01/13
Date: 1998-01-13T00:00:00+00:00 [thread overview]
Message-ID: <mheaney-ya023680001301981841260001@news.ni.net> (raw)
In-Reply-To: 34BC054C.5DB2@peak.org
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 <type derived
>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
<mailto:matthew_heaney@acm.org>
(818) 985-1271
next prev parent reply other threads:[~1998-01-13 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-01-07 0:00 Help on arrays of tagged types mrada
1998-01-09 0:00 ` Matthew Heaney
1998-01-09 0:00 ` Matthew Heaney
1998-01-13 0:00 ` James and Jessica Bear
1998-01-13 0:00 ` Matthew Heaney [this message]
1998-01-09 0:00 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox