comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
To: <comp.lang.ada@ada.eu.org>
Cc: <maa@liacc.up.pt>
Subject: Re: Heterogenous_Array_Test
Date: Tue, 14 Aug 2001 14:40:27 -0500
Date: 2001-08-14T14:40:27-05:00	[thread overview]
Message-ID: <mailman.997818026.5462.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: Pine.LNX.4.33.0108141912510.32177-100000@lagoa.niaad.liacc.up.pt

The following code compiles and executes correctly.

with Ada.Tags;
with Ada.Text_IO;
procedure Heterogeneous_Array_Test is

   type Root is tagged record
      Root_Component: Integer := 0;
   end record;

   type Child is new Root with record
      Child_Component: Integer := 0;
   end record;

   type Class_Ptr is access Root'Class;

   Item: array(1 .. 2) of Class_Ptr :=
     (1 => new Root,
      2 => new Child);

begin

   Item(1).Root_Component := 11;

   Item(2).Root_Component := 21;

   Child (Item(2).all).Child_Component := 22;

   for I in Item'Range loop
      Ada.Text_IO.Put_Line
        ("Type of Item (" & Positive'Image (I) & " ) is " &
         Ada.Tags.External_Tag (Item(i)'Tag));
   end loop;

end;

However, it does seem at first glance that the assignment to
Item (2),Child_Component should not have been ambiguous.

Perhaps one of the "language lawyers" reading this newsgroup
will explain it to us.

----- Original Message -----
From: "M. A. Alves" <maa@liacc.up.pt>
To: <comp.lang.ada@ada.eu.org>
Sent: Tuesday, August 14, 2001 3:12 PM
Subject: Heterogenous_Array_Test


> I am resuming an old thread (June 2001).  I was the original poster.
> Here I repost the problem with a summary review of the answers (to consult
> the entire old thread you may go to "http://groups.google.com/groups",
> search for "comp.lang.ada", then for "Heterogenous_Array_Test").  I do
> this because *** I found the answers inconclusive *** (I do this only now
> because of a conjugation of factors: I took some time trying to solve the
> problem by myself; I was changing offices then and my mail reading was out
> of order; the recent thread "Ambiguous reference - What is wrong with
> this?" seems to deal with similar issues).
>
> The problem is implementing an heterogenous array.  Candidate code:
>
>
> procedure Heterogenous_Array_Test is
>
>   type Root is tagged record
>     Root_Component: Integer := 0;
>   end record;
>
>   type Child is new Root with record
>     Child_Component: Integer := 0;
>   end record;
>
>   type Class_Ptr is access Root'Class;
>
>   Item: array(1 .. 2) of Class_Ptr := (
>     1 => new Root,
>     2 => new Child);
>
> begin
>
>   Item(1).Root_Component := 11;
>
>   Item(2).Root_Component := 21;
>
>   Item(2).Child_Component := 22;
>     -- error: no selector "Child_Component" for type "Root'Class"
>
> end;
>
>
> Ehud Lamm confirmed that "the approach is ok". The code has an error near
> the end.  Originally I asked for explanation of the error.  That was done.
> But no working solution was given.  Ted Dennison suggested changing the
> offending line to
>
>   Child'(Item(2).all).Child_Component := 22;
>
> That is intuitive (as was the original to me), but also does not compile.
> Ehud Lamm posted an example for derivation and dispatching, but NOT for
> the original problem of an heterogenous array.
>
> Thanks all very much,
>
> --
>    ,
>  M A R I O   data miner, LIACC, room 221   tel 351+226078830, ext 121
>  A M A D O   Rua Campo Alegre, 823         fax 351+226003654
>  A L V E S   P-4150 PORTO, Portugal        mob 351+939354002
>
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>




       reply	other threads:[~2001-08-14 19:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.33.0108141912510.32177-100000@lagoa.niaad.liacc.up.pt>
2001-08-14 19:40 ` David C. Hoos [this message]
2001-08-14 20:33   ` Heterogenous_Array_Test tmoran
2001-08-16 19:06 ` Heterogenous_Array_Test M. A. Alves
2001-08-14 20:12 Heterogenous_Array_Test M. A. Alves
2001-08-14 20:43 ` Heterogenous_Array_Test James Rogers
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox