From: Ludovic Brenta <ludovic.brenta@insalien.org>
Subject: Re: array of generic packages?
Date: Wed, 22 Sep 2004 20:26:40 +0200
Date: 2004-09-22T20:29:24+02:00 [thread overview]
Message-ID: <87zn3idusf.fsf@insalien.org> (raw)
In-Reply-To: 4151be92@dnews.tpgi.com.au
"a malkiel" writes:
> hi im somewhat new to ada. i've been trying to nut this one but can't seem
> to. Would anyone know if defining an "array of generic packages" is
> possible? What im looking for is something of the nature:
>
> type shape_type is (circle, triangle);
> package shapePointer(1) is new shape(circle);
> package shapePointer(2) is new shape(triangle);
>
> thanks in advance.
> ciao, andrew
No, you cannot have an array of generic packages. You can only have
arrays of objects; objects are constants and variables. You can
create a generic package that declares a new type of arrays, like so:
generic
type Element_Type is private;
package Generic_Arrays is
type Array_Type is array (Positive range <>) of Element_Type;
end Generic_Arrays;
type Triangle is ...
package Arrays_Of_Triangles is
new Generic_Arrays (Element_Type => Triangle);
My_Triangle : Triangle;
My_Array : Arrays_Of_Triangles.Array_Type := (1 => My_Triangle);
However, the generic package is not really all that useful if all you
want is to declare new array types. You'd be better off doing just:
type Array_Of_Triangles is array (Positive range <>) of Triangle;
type Array_Of_Circles is array (Positive range <>) of Circle;
which does not require a generic.
--
Ludovic Brenta.
next prev parent reply other threads:[~2004-09-22 18:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-22 18:03 array of generic packages? a malkiel
2004-09-22 18:26 ` Ludovic Brenta [this message]
2004-09-23 2:19 ` a malkiel
2004-09-22 23:30 ` Stephen Leake
2004-09-23 2:15 ` a malkiel
2004-09-24 12:39 ` Peter Hermann
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox