From: dog.ee.lbl.gov!overload.lbl.gov!agate!spool.mu.edu!nigel.msen.com!caen!de
Subject: Generic Package Visibility Problems! (help)
Date: 2 Oct 92 23:25:01 GMT [thread overview]
Message-ID: <1992Oct2.232501.1859@nntpd2.cxo.dec.com> (raw)
young@gdfwc3 (Mark Young) writes:
: I am having visibility problems with generic packages.
: Here's an example:
: file #1
: -----------------------------------------------
: generic
: Generic_Parameter : Generic_Parameter_Type;
: package Color is
: type RGB_Type is (RED,GREEN,BLUE);
: function Get_Color return RGB_Type;
: end Color;
: ----------------------------------------------
: file #2
: ----------------------------------------------
: with Color;
: package Caller is
: package C_1 is new Caller( Generic_Argument );
: procedure Test_Color;
: end Caller;
: package body Caller is
: procedure Test_Color is separate;
: end Caller;
: ---------------------------------------------
: file #3
: ---------------------------------------------
: separate( Caller )
: procedure Test_Color is
: begin
: if ( C_1.Get_Color = C_1.RED ) then
: -------
: null;
: end if;
: end Test_Color;
: ----------------------------------------------
: This will not work. For some reason the compiler cannot
: resolve C_1.RED. It tells me that = is not a legal
: operation, that C_1.Get_Color returns type RGB_Type but,
: that it does not understand C_1.RED and that perhaps I
: needed a "use" clause in the body of Caller. I don't
: understand this. My understanding of Ada scoping would
: lead me to believe that this is correct. Am I missing
: something?
:
: BTW: this is not a complete example, it is only to illustrate
: a point.
:
: Thanks,
:
: Mark Young
Well Mark,
This won't work for the following reasons:
1) You haven't used the generic formal in your generic package.
2) You have passed to the generic formal a very odd data type.
3) You are using a function in the body of TEST_COLOR wrong.
The following corrected program does what you want to do.
-- ++
-- file #1
-- --
generic
type GENERIC_PARAMETER_TYPE is (<>);
package COLOR is
RGB_TYPE : GENERIC_PARAMETER_TYPE;
function GET_COLOR return GENERIC_PARAMETER_TYPE;
end COLOR;
-- ++
-- file #2
-- --
with COLOR;
package CALLER is
type ZIPPY is ( RED, GREEN, BLUE );
package C_1 is new COLOR( ZIPPY );
procedure Test_Color;
end CALLER;
package body CALLER is
procedure TEST_COLOR is separate;
end CALLER;
---------------------------------------------
--file #3
---------------------------------------------
separate( CALLER )
procedure TEST_COLOR is
begin
if ( RED = C_1.GET_COLOR ) THEN
null;
end if;
end TEST_COLOR;
============================
Hope this helps!
Richard Wallace
Digital Equipment Corporation
301 Rockrimmon Blvd. South
CXO2-1/7A
Colorado Springs, CO 80919-2398
(719)548-2792
<wallace@cookie.enet.dec.com>
"The opinions expressed are my own, Uncle Ken or Uncle Bob
may, or may not, agree with me."
next reply other threads:[~1992-10-02 23:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-10-02 23:25 dog.ee.lbl.gov!overload.lbl.gov!agate!spool.mu.edu!nigel.msen.com!caen!de [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-10-04 22:10 Generic Package Visibility Problems! (help) DONALD PRINCIOTTA
1992-10-04 21:02 Adam Beneschan
1992-10-02 18:35 Mark Young
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox