comp.lang.ada
 help / color / mirror / Atom feed
From: "markww" <markww@gmail.com>
Subject: Re: how to import a package
Date: 11 Dec 2006 06:19:37 -0800
Date: 2006-12-11T06:19:37-08:00	[thread overview]
Message-ID: <1165846777.475130.199390@f1g2000cwa.googlegroups.com> (raw)
In-Reply-To: <1165830005.15844.5.camel@localhost>

Ok I just broke down and wrote the test function to take a specific
PERSON_REC type to add into a new node. The program compiles and runs
as expected, but I just lost my generics support by doing this, I
think:

    procedure Add_Record(GenericData : PERSON_REC) is
    Temp : gNode.Node_Ptr;
    begin

        Temp := new gNode.Node;
        Temp.Data := GenericData;
    end Add_Record;

So yes now it runs ok and I can print the contents of the linked list
and see that a person record was added into the Data member.

But now I can't use this Add_Record function to store some other type
of user defined data, it will only work with PERSON_RECs.

I'm sorry, I still don't understand how to just pass a generic through
as a parameter!

Thanks,
Mark



Georg Bauhaus wrote:
> On Sun, 2006-12-10 at 22:50 -0800, markww wrote:
> >  So I made a test function like:
> >
> >      procedure Add_Record(GenericData : gNode.T) is
> >      Temp : gNode.Node_Ptr;
> >      begin
> >          Temp := new gNode.Node;
> >          Temp.Data := GenericData;
> >      end Add_Record;
> >
> > now the compiler is saying that my generic type T is not visible to the
> > rest of the application.
>
> The type T is in the formal part of the package, not in the package
> proper. So either you are explicit about T (you have made an
> instance of the package using Some_Type for T, so you can use
> Some_Type instead of gNode.T there, too) or you make your generic
> package have a type Gen_T by using "subtype Gen_T is T" or similar.
>
>
> > Also, is this procedure definition correct? In C++ it's easy to do this
> > after defining a type it would be just:
> >
> >     bool Add_Record (T t);
> >     template<typename T>
> >     bool CLinkedList<T>::Add_Record(T t)
> >     {
> >         // ...
> >     }
> 
> But here, you have one specific T and one generic T.




  reply	other threads:[~2006-12-11 14:19 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 [this message]
2006-12-11 15:03                       ` Dmitry A. Kazakov
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