If you define a type Int_Array
in the specification (visible part) of package Package_1
, and you want to refer to that type in package Package_2
, you need to use with
clauses to make the type name visible:
with Package_1;
package Package_2 is
procedure Something (A : Package_1.Int_Array);
-- .........
end Package_2;
or
with Package_1; use Package_1;
package Package_2 is
procedure Something (A : Int_Array);
-- .........
end Package_2;
with Package_1
is needed to make anything defined in Package_1
available. Even then, you have to use a qualifier Package_1.
in front of any identifier defined there, to let the compiler know that's where to find it. use Package_1
means you can use the names defined in Package_1
without that qualifier. However, using use
can make it more difficult for a reader to tell where the names are coming from, especially if you use
too many packages. Different Ada programmers have different opinions about whether to use use
and when.
If this is not the issue, please post more information.
MORE: OK, since your packages are generic
, you have a rather different problem.
The generic package MultiStack
doesn't actually define a type IntArray
that you can use. The only way you can use it is to instantiate the generic. If you define Inst
to be an instance of the generic, like this:
package Inst is new MultiStack (Item => Some_Type, Put => Some_Put_Procedure);
then you can refer to Inst.IntArray
. But MultiStack.IntArray
is never going to be legal outside of MultiStack
itself.
So to get this to work with StackMove
, there are two possibilities, and you'll need to decide depending on what your needs are: (1) There will be a specific instance My_Multistack
that you've already instantiated, that StackMove
will work with; (2) more likely, you'd like StackMove
to work with any instance of MultiStack
. If (1) is correct, then just change MultiStack
to My_MultiStack
in stackmove.ads
. But if you want (2), you'll need a generic formal package:
with MultiStack;
generic
type Item is private;
with package Stack_Instance is new MultiStack(<>);
package StackMove is
procedure ReallocateArray (Base : in out Stack_Instance.IntArray);
end StackMove;
(You can put Item
and Stack_Instance
in either order.)
Doing the above won't guarantee that the Stack_Instance
was instantiated with the same Item
as StackMove
. If you want to guarantee that:
with MultiStack;
generic
type Item is private;
with package Stack_Instance is new MultiStack(Item => Item, Put => <>);
package StackMove is
procedure ReallocateArray (Base : in out Stack_Instance.IntArray);
end StackMove;
Then StackMove
will work only with a MultiStack
that was instantiated with the same Item
; the good news is that now the compiler can be certain that the two Item
types are the same, so you won't get type conflicts.
To instantiate, using the same Inst
example as above:
package Inst is new MultiStack (Item => Some_Type, Put => Some_Put_Procedure);
package StackMove_Inst is new StackMove (Item => Some_Type, Stack_Instance => Inst);
[The above two don't have to be together like that; they can be in different packages.]