comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: Some questions
Date: Thu, 10 Oct 2002 07:27:01 -0500
Date: 2002-10-10T07:27:01-05:00	[thread overview]
Message-ID: <mailman.1034252882.23717.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: 6c4a2b60cbe5ecf058fadca48f6c6e80.110780@mygate.mailgate.org


----- Original Message ----- 
From: "Sim Con" <sicon@hotmail.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, October 10, 2002 6:17 AM
Subject: Some questions


<snip>
> 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???
What you need to do is provide a print procedure when you instantiate the
generic.
This is done by declaring the generic like this:

generic
    type Item is private;
    with Procedure Print (I : Item) is <>;
package stacks
   type Stack is private;
.
   procedure Print (S : Stack);
.
end Stacks;

Then, when you instantiate the package, you do it specifying the type
if the items in the stack, and a print procedure for that type -- e.g.,:

package stack_float is new Stacks (float, print_float);

where print_float is your print procedure for the float type.

The <> in the generic declaration means that if there is a procedure
named Print visible at the point of instantiation, and having a parameter
profile matching that of the formal procedure parameter of your generic
declaration, then the instantiation can simply be
package stack_float is new Stacks (float);
because the matching print procedure will be included by default.

Then within your implementation of the generic package's Print procedure,
you can call the Print (I : Item) procedure for each item in the stack.






  reply	other threads:[~2002-10-10 12:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-10 11:17 Some questions Sim Con
2002-10-10 12:27 ` David C. Hoos [this message]
2002-10-10 13:34   ` Sim Con
2002-10-10 13:44     ` Colin Paul Gloster
2002-10-10 14:36     ` David C. Hoos
2002-10-10 14:18 ` Matthew Heaney
replies disabled

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