我正在使用 GNAT GPS studio IDE 来对 Ada 进行一些训练。我遇到了包可见性问题。
首先,我在名为“DScale.ads”的文件中指定一个包,其中包含以下类型:
package DScale is
type DMajor is (D, E, F_Sharp, G, A, B, C_Sharp);
end DScale;
然后,我在另一个文件(“Noteworthy.ads”)中指定一个包,该包定义将使用 DScale 包的 DMajor 类型的过程:
with Ada.Text_IO;
with DScale;
package NoteWorthy is
procedure Note;
end NoteWorthy;
最后,在“Noteworthy.adb”中,我提供了“Noteworthy”包的包体:
with Ada.Text_IO; use Ada.Text_IO;
package body Noteworthy is
procedure Note is
package ScaleIO is new Enumeration_IO(DScale.DMajor);
thisNote : DScale.DMajor := DScale.D;
begin
ScaleIO.Get(thisNote);
if thisNote = DScale.DMajor'First then
Put_Line("First note of scale.");
end if;
end Note;
begin
null;
end NoteWorthy;
如果我按原样保留代码,则“Noteworthy”包主体中的“if thisNote = DScale.DMajor'First then”语句将出现“操作符不直接可见”错误。
有没有办法在不使用“use”或“use type”子句的情况下绕过此错误?
谢谢。