comp.lang.ada
 help / color / mirror / Atom feed
From: James Rogers <jimmaureenrogers@worldnet.att.net>
Subject: Re: Heterogenous_Array_Test
Date: Tue, 14 Aug 2001 20:43:56 GMT
Date: 2001-08-14T20:43:56+00:00	[thread overview]
Message-ID: <3B798E23.8D5B7C03@worldnet.att.net> (raw)
In-Reply-To: mailman.997816290.5045.comp.lang.ada@ada.eu.org

"M. A. Alves" wrote:
> 
> 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).
> 

Note that you can create a heterogeneous array using access to
base'class.
The problem is that this creates a limited view of the array elements.
They are all viewed as being type Root. You must coerce the child
component back into its actual type to see the additional fields.

A heterogeneous array of this sort is most easily used when calling
overridden subprograms. This allows the subprogram calls to be
dynamically dispatched.

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;

  child(Item(2).all).Child_Component := 22;    
  -- error fixed
 
end;

Jim Rogers
Colorado Springs, Colorado USA



  reply	other threads:[~2001-08-14 20:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-14 20:12 Heterogenous_Array_Test M. A. Alves
2001-08-14 20:43 ` James Rogers [this message]
     [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
replies disabled

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