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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5fd1cba526594f4 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-10 07:18:45 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Some questions Date: Thu, 10 Oct 2002 10:18:36 -0400 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <6c4a2b60cbe5ecf058fadca48f6c6e80.110780@mygate.mailgate.org> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:29660 Date: 2002-10-10T10:18:36-04:00 List-Id: "Sim Con" wrote in message news:6c4a2b60cbe5ecf058fadca48f6c6e80.110780@mygate.mailgate.org... > > I have a generic stack and i want to print it but the element (the > generic part) could be integer or float so i think i can expand the > instantiated generic class with a child with only the right print > procedures, so i make this (for float, but the same for int): [snip] > package stack_float.print is > procedure Stampa(P: in Pila_int.pila); > end stack_float.print; > ------------------ > > the compilator says "child of an instance must be an instance or > renaming", so what's wrong? How can i build custom procedures for print > the generic elements in generic packages??? A generic can only have generic children, that are in turn instantiated, like this: generic with function Image (Element : Element_Type) return String is <>; procedure Stacks.Generic_Print (Stack : Stack_Type); You then have to instantiate it as a child of the instantiation of the parent, like this: with Stacks.Generic_Print; procedure Stack_Float.Print is new Stack_Float.Generic_Print (Float'Image); Alternatively, if your stack has a passive iterator, like this: generic type Element_Type is private; package Stacks is type Stack_Type is limited private; generic with procedure Process (Element : Element_Type) is <>; procedure Generic_Select_Elements (Stack : Stack_Type); ... end Stacks; then you can do this: S : Stack_Type; declare procedure Process (F : Float) is begin Float_Text_IO.Put (F); New_Line; end; procedure Print is new Generic_Select_Elements (Process); begin Print (Stack); end; If your stack has an active iterator, then you can do something like: S : Stack_Type; declare I : Iterator_Type := First (S); J : constant Iterator_Type := Back (S); begin while I /= J loop Float_Text_IO.Put (Element (I)); New_Line; I := Succ (I); end loop; end; So strictly speaking, you don't need a (generic) child procedure for printing. The Charles container library works like this (stack functionality is provided by the sequence containers (vectors, deques, lists), rather than by a specific stack abstraction). http://home.earthlink.net/~matthewjheaney/charles/index.html