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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b6751ae58ef95a4f X-Google-Attributes: gid103376,public From: Niklas Holsti Subject: Re: Generics and I/O Date: 1998/10/03 Message-ID: <3615F6F6.DD1D222D@icon.fi>#1/1 X-Deja-AN: 397319103 Content-Transfer-Encoding: 7bit References: Content-Type: text/plain; charset=us-ascii Organization: Sonera Corporation News Service Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-10-03T00:00:00+00:00 List-Id: William L Hayhurst wrote: > > Hi there. I have a question about Generics and IO. Given > > generic > type Item is private; > package Foo is > -- ... -- > procedure Print is > -- ... -- > Put( Item ); > -- ... -- > end Print; > end Foo; > > My compiler ( GNAT ) will flag the Put( Item ) as an error. [ rest snipped ] GNAT is correct; no Put operation is visible where you try to call it, in the generic. You need to supply a Put. Since the Item type is private, you should include this Put as a generic formal parameter: generic type Item is private; with procedure Put (I : in Item); package Foo is procedure Print (I : in Item); end Foo; Then, when you instantiate your generic, you supply the Put operation to be used, as shown in the code example below. I've used an enumeration type for Item, but I hope you get the point and can do the same for Integer. Note that it's not necessary to have a "wrapper" operation like MyPut. By placing the proper specification for "Put" in the generic part, you could instantiate Foo with MyItem_IO.Put directly. However, the Text_IO Put operations have additional parameters, such as Width, that must be included in the generic Foo Put specification for this to work. The instantiation can also find a suitable Put "automagically" by using the "<>" symbol in the generic spec, but I won't go into that. Hope this helps, - Niklas with Foo; with Text_IO; procedure Main is type MyItem is (This, That, TheOther); package MyItem_IO is new Text_IO.Enumeration_IO (MyItem); procedure MyPut (I : in MyItem) is begin Text_IO.Put ("MyPut: "); MyItem_IO.Put (I); Text_IO.New_Line; end MyPut; package MyFoo is new Foo (MyItem, MyPut); begin MyFoo.Print (That); end Main;