comp.lang.ada
 help / color / mirror / Atom feed
* Heterogenous_Array_Test
@ 2001-08-14 20:12 M. A. Alves
  2001-08-14 20:43 ` Heterogenous_Array_Test James Rogers
  0 siblings, 1 reply; 5+ messages in thread
From: M. A. Alves @ 2001-08-14 20:12 UTC (permalink / raw)
  To: comp.lang.ada

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






^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <Pine.LNX.4.33.0108141912510.32177-100000@lagoa.niaad.liacc.up.pt>]

end of thread, other threads:[~2001-08-16 19:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-14 20:12 Heterogenous_Array_Test M. A. Alves
2001-08-14 20:43 ` Heterogenous_Array_Test James Rogers
     [not found] <Pine.LNX.4.33.0108141912510.32177-100000@lagoa.niaad.liacc.up.pt>
2001-08-14 19:40 ` Heterogenous_Array_Test David C. Hoos
2001-08-14 20:33   ` Heterogenous_Array_Test tmoran
2001-08-16 19:06 ` Heterogenous_Array_Test M. A. Alves

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