Reputation: 638
I have the following program:
with Ada.Text_IO;
with pkg_task;
with pkg_procedure;
procedure exercise2 is
my_task : task_t;
begin
loop
my_task.ConsultsState;
end loop;
end;
which uses the following package pkg_task
:
with Text_IO;
package body pkg_task is
task body task_t is
entry IsEven(N: Integer) is
EvenConsult : Integer := 0;
OddConsult : Integer := 0;
begin
if N rem 2 = 0 then
Put_Line("Number " & N & " is even");
EvenConsult := EvenConsult + 1;
else
Put_Line("Number " & N & " is odd");
OddConsult := OddConsult + 1;
end if;
end IsEven;
entry ConsultsState is
begin
Put_Line("Total even numbers consulted: " & EvenConsult);
Put_Line("Total odd numbers consulted: " & OddConsult);
end ConsultsState;
end task_t;
end pkg_task;
when I compile, I get this error:
gcc-4.9 -c exercise2.adb
exercise2.adb:6:19: "task_t" is not visible
exercise2.adb:6:19: non-visible declaration at pkg_task.ads:2
exercise2.adb:9:17: invalid prefix in selected component "my_task"
gnatmake: "exercise2.adb" compilation error
I don't know how to fix it.
Upvotes: 0
Views: 244
Reputation: 1133
This is the difference between scope and visibility.
with pkg_task;
means that this pkg_task
is now in your scope, but its elements are not directly visible.
Therefore, in order to use task_t
you can either prefix it with the package name : pkg_task.task_t
, or make the type visible with a use clause (use pkg_task;
).
For more information on this topic, you can check Ada Distilled.
Upvotes: 4