Ada:运算符不直接可见 [英] Ada : operator is not directly visible

查看:116
本文介绍了Ada:运算符不直接可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GNAT GPS studio IDE以便对Ada进行一些培训.我的包裹可见性有问题.

I'm using GNAT GPS studio IDE in order to train a bit in Ada. I'm having an issue with package visibility.

首先,我在名为"DScale.ads"的文件中指定一个包含以下类型的包:

First I specify a package in a file called "DScale.ads" containing a type:

package DScale is 
   type DMajor is (D, E, F_Sharp, G, A, B, C_Sharp);
end DScale;

然后,我在另一个文件("Noteworthy.ads")中指定一个程序包,该程序包定义将使用DScale程序包的DMajor类型的过程:

Then I specify in a different file ("Noteworthy.ads") a package that defines a procedure that will use the DMajor type of the DScale package:

with Ada.Text_IO;
with DScale;

package NoteWorthy is 
   procedure Note;
end NoteWorthy;

最后,在"Noteworthy.adb"中,为软件包"Noteworthy"提供了软件包主体:

Finally in "Noteworthy.adb" I provide the package body for the package "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;


如果按原样保留代码,则在值得注意的"包的正文中,"ifthisNote = DScale.DMajor'First then"语句将收到操作员无法直接看到"错误.


If I leave the code as-is, I will get an "operator not directly visible" error for the "if thisNote = DScale.DMajor'First then" statement in the body of the "Noteworthy" package.

是否有一种无需使用"use"或"use type"子句来绕过此错误的方法?

Is there a way to bypass this error without using a "use" or "use type" clause?

谢谢.

推荐答案

您的问题(至少)有两个答案.

There are (at least) two answers to your question.

1:

if DScale."=" (thisNote, DScale.DMajor'First) then

2:

function "=" (Left, Right : DScale.DMajor) return Boolean renames DScale.DMajor;
...
if thisNote = DScale.DMajor'First then

但是您为什么要使用这些选项之一而不是:

But why would you use one of those options instead of:

use type DScale.DMajor;
...
if thisNote = DScale.DMajor'First then

这篇关于Ada:运算符不直接可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆