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,8fdcbb4347c7f20a X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Instantiation of child generics? Date: 1996/07/26 Message-ID: #1/1 X-Deja-AN: 170884668 references: <4t9itp$imd@goanna.cs.rmit.edu.au> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-26T00:00:00+00:00 List-Id: In article <4t9itp$imd@goanna.cs.rmit.edu.au>, Dale Stanbrough wrote: >Hi, > >I'ld like to create an abstract generic queue package with bounded >and unbounded children. However I have been thwarted in all attempts >to instantiate them. Also I don't really understand the rules for >instantiaion of child generics. Can anyone explain them? > > >e.g. > > generic > type element is private; > package queues is > type queue is abstract tagged null record; > > procedure init return queue is abstract; > > procedure enqueue(item:in out queue; item:element) is abstract; > > -- etc > end queues; > > > generic > size :natural; > package queues.bounded is > > type queue is new queues.queue with private; > > procedure init return queue is abstract; > > procedure enqueue(item:in out queue; item:element) is abstract; > > private > type queue is new queues.queue with null record; -- for now... > end; > > >How do I instantiate this? > > with queues.bounded; > package myQ is new queues.bounded(integer, 5); You need to instantiate the parent first: with queues; package integer_queues is new queus(element => integer); Now, conceptually, for every child of queues, there is a generic child of integer_queues. But these are not visible unless you "with" the corresponding child of queues. Also, they are somewhat mythical -- the compiler will normally not create them unless needed (now can it? -- it can't know about all those children at compile time). with integer_queues; with queues.bounded; -- Makes Integer_Queues.Bounded visible. package bounded_integer_queues is new integer_queues.bounded(size => 5); Or, you could make the instance a child: with integer_queues; with queues.bounded; package integer_queues.bounded_integer_queues is new integer_queues.bounded(size => 5); -- You can't call this instance integer_queues.bounded, because -- that's the name of a generic. Or, you could nest them inside another package: with queues; -- Not strictly necessary, but I like to write this. with queues.bounded; package My_Queues is package int_queues is new queus(element => integer); -- Here, int_queues.bounded is visible, because queues.bounded -- is "with"ed, so we can instantiate it: package bounded is new int_queues.bounded(size => 5); ... end My_Queues; >results in Gnat telling me "invalid prefix in selected component "queues"" > >Also will my (re)use of the identifier "queue" in the packages cause any >problems for me? Should be OK, but I don't particularly like that style. - Bob