Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: using put p...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 5 Topic 5688 of 5830
Post > Topic >>

Re: using put procedure with a generic package

by "ophir.geffen@[EMAIL PROTECTED] " <ophir.geffen@[EMAIL PROTECTED] > May 7, 2008 at 09:48 PM

On May 8, 7:09 am, "Jeffrey R. Carter"
<spam.jrcarter....@[EMAIL PROTECTED]
> wrote:
> ophir.gef...@[EMAIL PROTECTED]
 wrote:
>
> > * queues.ads:
> > with Ada.Text_IO;
> > generic
> >   type Item is private;
> >   with procedure Item_Put(The_Item : in Item);
>
> Item_Put has exactly one parameter.
>
> >   package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
> >   package Int_Queues is new Queues(Item => Integer, Item_Put =>
> > Int_IO.Put); --- error here
>
> > The package compiles on its own, but when I try to compile Test_Queues
> > there is an error:
> > no visible subprogram matches the specification for "Item_Put"
>
> Ada.Text_IO.Integer_IO has the following procedures named Put:
>
> procedure Put(File  : in File_Type;
>                Item  : in Num;
>                Width : in Field       := Default_Width;
>                Base  : in Number_Base := Default_Base);
>
> procedure Put(Item  : in Num;
>                Width : in Field       := Default_Width;
>                Base  : in Number_Base := Default_Base);
>
> procedure Put(To   :    out String;
>                Item : in     Num;
>                Base : in     Number_Base := Default_Base);
>
> None of these has exactly one parameter. That's why Int_IO.Put doesn't
match
> Item_Put.
>
> You can call the 2nd of these with only one explicit parameter:
>
> Int_IO.Put (Item => 7);
>
> but it still has 3 parameters; the other 2 get the default values as the
actual
> parameters.
>
> You need to create a procedure that matches Item_Put:
>
> procedure Put (Item : in Integer) is
>     -- null;
> begin -- Put
>     Int_IO.Put (Item => Item);
> end Put;
>
> and use it to instantiate your generic package.
>
> --
> Jeff Carter
> "I unclog my nose towards you."
> Monty Python & the Holy Grail
> 11

Hi
Thanks for the quick reply

The problem is that the package needs to know how to handle most non-
limited types like Integer, String, Client, Plane, Book, Do***ent, ...
The Put procedure in any of those might and should be different from
Put Integer.

And I don't want to force the package user to declare a special Put
procedure with only one var.
Is there a better way to write the package and/or a more correct way
to declare it when using it?
 




 5 Posts in Topic:
using put procedure with a generic package
"ophir.geffen@[EMAIL  2008-05-07 20:27:19 
Re: using put procedure with a generic package
"Jeffrey R. Carter&q  2008-05-08 04:09:25 
Re: using put procedure with a generic package
"ophir.geffen@[EMAIL  2008-05-07 21:48:47 
Re: using put procedure with a generic package
"Dmitry A. Kazakov&q  2008-05-08 09:24:53 
Re: using put procedure with a generic package
Adam Beneschan <adam@[  2008-05-08 08:54:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 14:49:52 CDT 2008.