comp.lang.ada
 help / color / mirror / Atom feed
From: rcollinson@my-deja.com
Subject: Re: Calling generic children from their parent?
Date: 1999/07/01
Date: 1999-07-01T00:00:00+00:00	[thread overview]
Message-ID: <7lgnku$ps4$1@nnrp1.deja.com> (raw)
In-Reply-To: 3773C090.F177F565@averstar.com

In article <3773C090.F177F565@averstar.com>,
  Tucker Taft <stt@averstar.com> wrote:
> rcollinson@my-deja.com wrote:
> > ...
> > 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!!!
>
> You will need to move all of your type extensions into the (private
> part of the) generic spec.
>
> One way you can accomplish that is to change P.C from
> being a child to being a separate generic, with a formal tagged type
> as a parameter.  E.g.:
>
>  generic
>    type P_T is tagged private;
>    --... Other formal params as necessary to make up for not being a
child
>  package P_C is
>    type T is new P_T with
>      record
>        B : integer;
>      end record;
>  end P_C;
>
>  with P_C;
>  generic
>  package P is
>    type T is tagged
>     record
>       A : integer;
>     end record;
>    procedure Dummy;
>  private
>    package Child is new P_C(T);
>    type Nt is new Child.T with null record;
>  end P;
>
>  package body P is
>    procedure Dummy is
>      X : Nt;
>    begin
>      null;
>    end Dummy;
>  end P;
>
> --
> -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
>


Thanks for the help with this!

I used a private child class with private operations to implement the
solution.  It uses private dispatching which I found to be pretty cool.
I made a public class-wide create function that returns a class object
the caller can pass to the public operations and unknown to him will
dispatch if necessary.

Thanks again!


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




  reply	other threads:[~1999-07-01  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 ` Dale Stanbrough
1999-06-23  0:00   ` rcollinson
1999-06-24  0:00     ` Tucker Taft
1999-06-24  0:00       ` rcollinson
1999-06-25  0:00         ` Tucker Taft
1999-07-01  0:00           ` rcollinson [this message]
1999-06-23  0:00 ` Matthew Heaney
replies disabled

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