comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@acm.org>
To: comp.lang.ada@ada-france.org
Subject: Re: generic with procedure
Date: 28 Sep 2004 19:56:25 -0400
Date: 2004-09-28T19:56:25-04:00	[thread overview]
Message-ID: <mailman.127.1096415795.390.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <cjcmeu$ljq$03$1@news.t-online.com>

"Rick Santa-Cruz" <rick_santa_cruz75@msn.com> writes:

> Hi,
> 
> I am starting to read a bit about generic programming and I am a bit 
> confused from it, cause it seems to me a bit different to 
> template-programming in C++.
> Sadly I can't figure out the difference between the following:
> 1.) generic
>         type Element is private;
>     package MyContainers is
>         type MyContainer is private;
>         procedure Some_Proc(Item : Element);
>     end MyContainer;

This is a complete package spec.

> 2.) generic
>         type Element is private;
>     package MyContainers is
>         type MyContainer is private;
>      generic
>         with procedure Some_Proc(Item : Element);
>     end MyContainer;

This is not legal syntax. You could mean:

2a.)
generic
   type Element is private;
package MyContainer_2a is
   type MyContainer is private;
   
   generic
      with procedure Some_Proc(Item : Element);
   procedure Foo;
end MyContainer_2a;

or 

2b.)
generic
   type Element is private;
package MyContainer_2b is
   type MyContainer is private;
   
   generic
   procedure Some_Proc(Item : Element);
   
end MyContainer_2b;


In 2a, 'Foo' is a generic procedure, that requires a generic formal
procedure parameter; presumably Foo calls Some_Proc in its body.

In 2b, 'Some_Proc' is a generic procedure, with no generic formal
parameters.

Here are some legal instantiations:

package Container_2a is new My_Container_2a (Integer);

procedure Proc (Item : Element) is 
    Put_Line ("hello 2a");
end Proc;

procedure Bar is new Container_2a.Foo (Proc);



package Container_2b is new My_Container_2b (Integer);

procedure Proc is new Container_2b.Some_Proc;

-- 
-- Stephe




  reply	other threads:[~2004-09-28 23:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-28 21:52 generic with procedure Rick Santa-Cruz
2004-09-28 23:56 ` Stephen Leake [this message]
2004-09-29  0:06   ` Rick Santa-Cruz
2004-09-29 23:47     ` Stephen Leake
2004-09-29  2:11 ` Georg Bauhaus
replies disabled

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