comp.lang.ada
 help / color / mirror / Atom feed
From: rcollinson@my-deja.com
Subject: Re: Calling generic children from their parent?
Date: 1999/06/24
Date: 1999-06-24T00:00:00+00:00	[thread overview]
Message-ID: <7kucc8$jfg$1@nnrp1.deja.com> (raw)
In-Reply-To: 37723E5B.53577638@averstar.com

In article <37723E5B.53577638@averstar.com>,
  Tucker Taft <stt@averstar.com> wrote:
> rcollinson@my-deja.com wrote:
> > ...
> > My problem is that I TRY to instantiate a generic
> > child unit inside the body of the parent and it
> > will not compile.  The text Rendezvous with Ada 95
> > states this is possible on page 337 but I have
> > been unable to make it work.  (On a slightly
> > different subject, why in the example on page 337
> > do they WITH and ELABORATE Generic_Parent.Child in
> > the last exerpt?)
>
> If you can post a small self-contained example with the
> accompanying error message you received from the compiler,
> I suspect someone could quickly point out the solution to your
problem.
>
> Here is an example that should work:
>
>    generic
>    package P is
>        procedure Dummy;
>    end P;
>
>    generic
>    package P.C is
>        type T is null record;
>    end P.C;
>
>    with P.C;
>    package body P is
>       package Child is new P.C;
>       type NT is new Child.T;
>       procedure Dummy is
>           X : NT;
>       begin
>           null;
>       end;
>      -- ...
>    end P;
>
> Note that you normally have to instantiate all ancestors
> of a child of a generic before instantiating the child.
> However, when inside the parent generic, the name of the
> parent generic itself represents the "current instance",
> and hence you don't need to instantiate the parent generic inside
> itself to be able to instantiate the child.
>
> > Roger
>
> --
> -Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
> Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
> AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA
>

The problem was that I was using a tagged type.  Code follows:

generic
package P is
 type T is tagged
   record
     A : integer;
   end record;
  procedure Dummy;
end P;

generic
package P.C is
  type T is new P.T with
    record
      B : integer;
    end record;
end P.C;

with P.C;
package body P is
  package Child is new P.C;  --  This does not compile.
  type Nt is new Child.T;
  procedure Dummy is
    X : Nt;
  begin
    null;
  end Dummy;
end P;

-- Compilation error is:
-- Child is illegal because the type extension P.Child.T shall not be
declared in a generic body if the parent type is declared outside that
body.

*** Any ideas how to get around this???  Thanks!!!


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




  reply	other threads:[~1999-06-24  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-23  0:00 Calling generic children from their parent? RCollinson
1999-06-23  0:00 ` Matthew Heaney
1999-06-23  0:00 ` Dale Stanbrough
1999-06-23  0:00   ` rcollinson
1999-06-24  0:00     ` Tucker Taft
1999-06-24  0:00       ` rcollinson [this message]
1999-06-25  0:00         ` Tucker Taft
1999-07-01  0:00           ` rcollinson
replies disabled

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