我正在使用GNAT GPS studio IDE以便在Ada中进行一些培训。我在软件包可见性方面遇到问题。
首先,我在名为“ DScale.ads”的文件中指定一个包含以下类型的包:
package DScale is
type DMajor is (D, E, F_Sharp, G, A, B, C_Sharp);
end DScale;
Run Code Online (Sandbox Code Playgroud)
然后,在另一个文件(“ Noteworthy.ads”)中指定一个包,该包定义了将使用DScale包的DMajor类型的过程:
with Ada.Text_IO;
with DScale;
package NoteWorthy is
procedure Note;
end NoteWorthy;
Run Code Online (Sandbox Code Playgroud)
最后,在“ 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;
Run Code Online (Sandbox Code Playgroud)
如果按原样保留代码,则“ Noteworthy”包正文中的“ if …