comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <dont.bother.mcondic.auntie.spam@[acm.org>
Subject: Re: Package Instances???
Date: Wed, 13 Feb 2002 16:46:23 -0500
Date: 2002-02-13T21:46:24+00:00	[thread overview]
Message-ID: <a4emrg$kd0$1@nh.pace.co.uk> (raw)
In-Reply-To: 721b6d80.0202131302.1ccce2ed@posting.google.com

Sounds like you're trying to treat a package as if it was a C++ class and
you're trying to create a new instance of it because it presumably holds a
set of variables you want to duplicate? First, as you discovered, you can't
do that. Second, it isn't really the right idiom for Ada.

The way to do it would be to have a record type declared in the package that
holds all your variables. Then you create objects of the record type & use
the operations contained in the package on the individual objects of that
type. Something like this:

package My_Package is
    type My_Rec is record
        A    : Integer ;
        B    : Integer ;
        C    : Integer ;
    end record ;
    function Some_Operation (Rec : My_Rec) return Integer ;
end My_Package ;

--  Then in the unit that uses it...

X : My_Package.My_Rec ;  --  One instance of the A, B, C variables
Y : My_Package.My_Rec ;  --  A whole different instance of them.
.......
--  Operates on X.A, X.B, X.C
Some_Int := My_Package.Some_Operation (X) ;
.......
--  Operates on Y.A, Y.B, Y.C
Another_Int := My_Package.Some_Operation (Y) ;
.......


If that's what you were trying to accomplish, I hope this clarifies. If it
was something else, see if you can explain what you are trying to do and
maybe we can help you find The Ada Way of doing it.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Yates" <yates_1900@yahoo.com> wrote in message
news:721b6d80.0202131302.1ccce2ed@posting.google.com...
> I am new to Ada. I'd like to know if it is possible to create multiple
> instances of a package. For example, if I have a package 'My_Package',
can
> I do something like:
>
> p1 : My_Package := new My_Package
> p2 : My_Package := new My_Package
> .....
>
> I tried this and didn't work. Is there other ways to do it?
>
> Thanks
>
> Yates





  parent reply	other threads:[~2002-02-13 21:46 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-13 21:02 Package Instances??? Yates
2002-02-13 21:12 ` Larry Kilgallen
2002-02-13 21:21 ` chris.danx
2002-02-13 21:46 ` Marin David Condic [this message]
2002-02-14 17:59   ` Hyman Rosen
2002-02-15 13:11     ` Marc A. Criley
2002-02-15 19:20     ` Simon Wright
2002-02-19 14:08       ` Marin David Condic
2002-02-20  1:37         ` Matthew Heaney
2002-02-20 16:56           ` Marin David Condic
2002-02-21 15:33             ` Matthew Heaney
2002-02-20 19:16           ` Hyman Rosen
2002-02-20 22:31             ` Pat Rogers
2002-02-20 23:44             ` Matthew Heaney
2002-02-21  5:35               ` Hyman Rosen
2002-02-21 14:05                 ` Marin David Condic
2002-02-22 16:49                   ` Hyman Rosen
2002-02-22 17:22                     ` Marin David Condic
2002-02-24  7:39                       ` Hyman Rosen
2002-02-25 15:38                         ` Matthew Heaney
2002-02-22 18:10                     ` Matthew Heaney
2002-02-22 20:55                       ` Hyman Rosen
2002-02-22 21:37                         ` Matthew Heaney
2002-02-24  7:36                           ` Hyman Rosen
2002-02-25 15:27                             ` Matthew Heaney
2002-02-21 15:30                 ` Matthew Heaney
2002-02-21 18:05                   ` Hyman Rosen
2002-02-13 21:50 ` Eric Merritt
2002-02-14 15:08 ` Yates
replies disabled

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