From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: how to import a package
Date: Mon, 11 Dec 2006 16:03:00 +0100
Date: 2006-12-11T16:03:00+01:00 [thread overview]
Message-ID: <4ahvv5zjwjhc$.17letwewzun6c$.dlg@40tude.net> (raw)
In-Reply-To: 1165846777.475130.199390@f1g2000cwa.googlegroups.com
On 11 Dec 2006 06:19:37 -0800, markww wrote:
> I'm sorry, I still don't understand how to just pass a generic through
> as a parameter!
No way. It is incorrect in either C++ or Ada. A generic is never a [normal]
parameter. It can only be a *generic* parameter of another generic thing.
Answering less formally, what you want to achieve is probably this:
generic
type T is private;
package Generic_List is
type Node;
type Node_Ptr is access Node;
type Node is limited record -- We don't copy nodes
Data : T; -- The data in the node
Prev : Node_Ptr; -- Previous node, else null
Next : Node_Ptr; -- Next node, else null
end record;
-- Operations defined on the nodes follow:
--
-- Add a new node to the list after the node indicated by
-- the parameter After.
--
procedure Add (After : Node_Ptr; Data : T);
end Generic_List;
----------------------------------------------
package body Generic_List is
procedure Add (After : Node_Ptr; Data : T) is
New_Node : Node_Ptr := new Node;
begin
New_Node.Data := Data;
New_Node.Prev := After;
New_Node.Next := After.Next;
if After.Next /= null then
After.Next.Prev := New_Node;
end if;
After.Next := New_Node;
end Add;
end Generic_List;
-------------------------------------------
1. T is a generic formal parameter of the package Generic_List.
2. Data is normal parameter of a procedure Add.
3. The procedure Add is not generic
4. When Generic_List is instantiated this instance will be a normal package
with a normal procedure Add in it.
5. This Add will be defined on the actual type specified for T during the
instantiation.
For example:
package List_Of_Integers is new Generic_List (T=>Integer);
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2006-12-11 15:03 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-06 2:14 how to import a package markww
2006-12-06 3:06 ` Adam Beneschan
2006-12-06 3:34 ` markww
2006-12-06 9:18 ` Simon Wright
2006-12-06 19:47 ` Jeffrey R. Carter
2006-12-06 23:56 ` markww
2006-12-07 1:18 ` Björn Persson
2006-12-07 1:26 ` Brian May
2006-12-07 4:14 ` markww
2006-12-07 4:40 ` Brian May
2006-12-07 9:32 ` Stuart
2006-12-07 11:21 ` Jean-Pierre Rosen
2006-12-11 6:16 ` markww
2006-12-11 6:50 ` markww
2006-12-11 9:40 ` Georg Bauhaus
2006-12-11 14:19 ` markww
2006-12-11 15:03 ` Dmitry A. Kazakov [this message]
2006-12-11 16:22 ` Adam Beneschan
2006-12-11 20:28 ` Jeffrey R. Carter
2006-12-12 3:19 ` markww
2006-12-12 3:31 ` Jeffrey R. Carter
2006-12-12 9:03 ` Stuart
2006-12-12 10:56 ` Georg Bauhaus
2006-12-11 7:00 ` Simon Wright
2006-12-07 4:06 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox