comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Ada: Inheritance of generics
Date: Mon, 2 Jun 2008 08:13:09 -0700 (PDT)
Date: 2008-06-02T08:13:09-07:00	[thread overview]
Message-ID: <1755c5d8-8c27-4219-8670-80086f098ba5@a32g2000prf.googlegroups.com> (raw)
In-Reply-To: g20vec$1k1$1@aioe.org

On Jun 2, 7:17 am, Dennis Hoppe <dennis.ho...@hoppinet.de> wrote:
> Dmitry A. Kazakov wrote:
> > On Mon, 02 Jun 2008 15:39:05 +0200, Dennis Hoppe wrote:
>
> >> -- child unit
> >> generic
> >>    -- omitted
> >> package Generic_Child is
> >>    type Object is new Generic_Parent.Object with private;
>
> > This is illegal. Generic_Parent is a generic unit, you cannot refer to
> > anything within it without either instantiation of, or else from a generic
> > child unit of. Generic_Child is not a child package of Generic_Parent.
>
> Hmm...this line is really a left over from simple inheritance without
> generic unit, but the Ada compiler does not complain about it.
>
> > P.S. Except for trivial cases, it is always better to post complete code
> > samples.
>
> I thought, this example was exhaustive: parent, child, instantiation.

"Complete code sample" means something that you can compile.  In this
case, it's hard to tell what you're trying to do.  If your units are
all top-level library units, there's a lot of WITH's missing; plus
2**16 is not a type, so you can't instantiate Generic_Package with it,
and there's no completion for the private type extension Object,
you've tried to instantiate a type instead of a generic package.
Sometimes it's good enough to leave stuff out, but in this case I
can't tell what you're trying to do, and I suspect I'm not alone.

There's so many things wrong with this code that I'm just going to
take a guess at what you're trying to do and hope it's close to what
you're looking for.  If not, you'll need to explain more about what
you're trying to accomplish.  The following Ada source does compile.

generic
   type Modular_Type is mod <>;
package Generic_Parent is
   type Object is abstract tagged limited null record;

   function Example return Integer;
end Generic_Parent;

-- child unit
generic
   -- omitted
package Generic_Parent.Generic_Child is
   type Object is new Generic_Parent.Object with private;

   function Example return Integer;
private
   type Object is new Generic_Parent.Object with null record;
       -- or whatever you want in the type extension
end Generic_Parent.Generic_Child;

package Mod_Package is
   type Unsigned_16 is mod 2**16;
end Mod_Package;

with Generic_Parent;
with Mod_Package;
package Parent is new Generic_Parent (Mod_Package.Unsigned_16);

with Parent;
with Generic_Parent.Generic_Child;
package Child is new Parent.Generic_Child;

with Child;
package Pak1 is
   A : Integer := Child.Example;
end Pak1;

                          -- HTH, Adam



  parent reply	other threads:[~2008-06-02 15:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-02 13:39 Ada: Inheritance of generics Dennis Hoppe
2008-06-02 13:51 ` Dmitry A. Kazakov
2008-06-02 14:17   ` Dennis Hoppe
2008-06-02 14:34     ` Georg Bauhaus
2008-06-02 15:09     ` Dmitry A. Kazakov
2008-06-02 15:13     ` Adam Beneschan [this message]
2008-06-02 21:10       ` Dennis Hoppe
2008-06-02 14:30 ` Georg Bauhaus
replies disabled

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