From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,bb8516c9e7650bc8 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Passing an instance of a generic child as a generic parameter Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Sun, 15 Jun 2008 11:04:16 +0200 Message-ID: <17dp09yvw69tz.v0lkd9ukna30$.dlg@40tude.net> NNTP-Posting-Date: 15 Jun 2008 11:04:16 CEST NNTP-Posting-Host: d8cf4b38.newsspool4.arcor-online.net X-Trace: DXC=QSZ5^[4G\B3;]cDoEWD6A44IUK\BH3Y2NbJ\lX_>gN=DNcfSJ;bb[5IRnRBaCdI\HHV;]m>==ZJ;i?lUmLO4 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:713 Date: 2008-06-15T11:04:16+02:00 List-Id: On Sun, 15 Jun 2008 10:57:44 +0200, Dmitry A. Kazakov wrote: > On Sat, 14 Jun 2008 22:54:46 +0200, Dennis Hoppe wrote: > >> I'm trying to pass an instance of a generic child unit to another >> generic package, but the only syntax, I could found specifies a concrete >> generic package. > > Ada does not have interfaces of packages. A generic child package is not an > implementation of the parent's package interface, which could then be > referenced as a formal parameter of some other generic package. So the > answer is no. > > But it seems to me that your example does not require that stuff: > >> Let's first have a look at my pathological example: >> >> -- GENERIC PARENT 'other' ADS >> generic >> B : Integer; >> package Other is >> type Object is tagged null record; >> procedure Solve (Obj : Object); >> end Other; >> >> >> -- GENERIC PARENT 'other' ADB >> with Ada.Text_IO; >> >> package body Other is >> procedure Solve (Obj : Object) is >> begin >> Ada.Text_IO.Put_Line ("solved"); >> end; >> end Other; >> >> -- GENERIC CHILD of 'other' ADS >> with Other; >> >> generic >> -- omitted >> package Other.Child is >> type Instance is new Other.Object with null record; >> >> overriding >> procedure Solve (Obj : in Instance); >> end Other.Child; >> >> -- GENERIC CHILD of 'other' ADB >> with Ada.Text_IO; >> >> package body Other.Child is >> procedure Solve (Obj : in Instance) is >> begin >> Ada.Text_IO.Put ("other child"); >> end; >> end Other.Child; >> >> -- GENERIC PARENT 'parent' ADS >> with Other; >> >> generic >> A: Integer; >> with package XX is new Other (A); > > type Object is new XX.Object with null record; type Object is new XX.Object with private; -- Of course >> parent Parent is >> type Object is abstract tagged null record; > > remove this > >> procedure Print (Obj: in Object; X : in XX.Object'Class); >> end Parent; > > Now Parent takes an instance of Other, which determines the class of > Objects to use. The class is parametrized by A. The formal type Object is > an instance from the class to deal with. > > BTW, you could also remove the parameter A: > > generic > with package XX is new Other (<>); -- Brings some A with it > type Object is new XX.Object with null record; > >> parent Parent is > > [...] > >> procedure Test is >> A : Integer := 2; >> package O is new Other (A); >> package E is new O.Child; >> package P is new Parent (A, E); -- O is replaced by the child E >> .. -- compiler error expected > > package P is new Parent (A, O, E.Instance); -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de