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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,78f8f7e576439a69 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-14 12:40:51 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!195.64.68.27!newsgate.cistron.nl!isdnet!enst!enst.fr!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada Subject: Re: Heterogenous_Array_Test Date: Tue, 14 Aug 2001 14:40:27 -0500 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 997818050 8453 137.194.161.2 (14 Aug 2001 19:40:50 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Tue, 14 Aug 2001 19:40:50 +0000 (UTC) Cc: To: Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.4 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:11933 Date: 2001-08-14T14:40:27-05:00 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" To: 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 >