Ada与Get的歧义表达

如何解决Ada与Get的歧义表达

我正在尝试使用IOredirection创建,添加,删除和打印两个数组,其中之一是整数,另一个是使用泛型的浮点数。

对于整数数组来说一切都很好,但是在“ get(fVal)”处出现错误“歧义表达式(无法解析“ Get”)。

我认为这可能与在整数数组之后的float数组有关。我将其放在整数数组之前,但对于浮点数组仍然遇到相同的错误。

我还是Ada的新手,所以有时我很难去掌握它。

with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Float_Text_IO;
use Ada.Float_Text_IO;
with CreateList;

procedure Main is

   package IntIO is new Ada.Text_IO.Integer_IO(Integer); use IntIO;
   package FloatIO is new Ada.Text_IO.Float_IO(Float); use FloatIO;

begin

   declare
      max: integer;   --declaring integer named "max"
      val: integer;
      del: integer;
      pointer : integer := 0;
      len : integer := 0;
      procedure MyPut(x: integer) is begin
            IntIO.Put(x,10);
      end MyPut;

      package C_List is new CreateList(max,integer,MyPut); use C_List;

   begin
      get(max);                              --assigns input for array size and assigns value to "max"
      for row in 1 .. max loop
         get(val);
         C_List.add_to_list(val);            --calls procedure to add value 12 to array
      end loop;
      C_List.print_list;                     --calls procedure to print entire array
      len := C_List.length_of_list;          --calls function to determine the current length of array and assign the value to "len"
      for pointer in 1 .. len loop           --calls procedure to print individual value in array. Loops to print all values in array
         C_List.print_list(pointer);
      end loop;
      Put_Line("");
      get(del);
      C_List.delete_from_list(del);          --calls procedure to delete a value from array
      C_List.print_list;                     --calls procedure to print entire array
   end;

   

   declare
      max: integer;   --declaring integer named "max"
      fVal: float;
      del: integer;
      pointer : integer := 0;
      len : integer := 0;
      
      procedure MyPut(x: Float) is begin
         FloatIO.Put(x,0);
      end MyPut;


      package B_List is new CreateList(max,float,MyPut); use B_List;

      begin
         get(max);                           --assigns input for array size and assigns value to "max"
      for row in 1 .. max loop
         get(fVal);
         B_List.add_to_list(fVal);           --calls procedure to add value 12 to array
      end loop;
         B_List.print_list;                  --calls procedure to print entire array
         len := B_List.length_of_list;       --calls function to determine the current length of array and assign the value to "len"
         for pointer in 1 .. len loop        --calls procedure to print individual value in array. Loops to print all values in array
            B_List.print_list(pointer);
         end loop;
         Put_Line("");
         get(del);
         B_List.delete_from_list(del);       --calls procedure to delete a value from array
         B_List.print_list;                  --calls procedure to print entire array
      end;

end Main;

createlist.adb

with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Float_Text_IO;
use Ada.Float_Text_IO;

package body CreateList is
   len: Integer;                       --declaring integer named "len"
   list: array(1..max) of itemType;    --making an integer array named "list"
   pnt: integer;                       --declaring integer named "pnt"

   procedure add_to_list (ListItem: in itemType) is begin   --procedure that adds new integer value to array "list"
      if pnt >= max then                                    --detects when array is full and can't fit more values
         Put_Line("**Detected Overflow**");
      else
         pnt := pnt + 1;                                    --moves pointer
         list(pnt) := ListItem;                             --adds new integer value to pointer index
      end if;
   end add_to_list;

   procedure delete_from_list (indx: in Integer) is begin   --procedure that removes an integer value from array "list"
      if indx = 0 then                                      --detects when array is empty and doesn't have any values to delete
         Put_Line("**Detected Underflow**");
      else
         for j in indx .. (pnt - 1) loop                    --loop to pop the stack after an integer has been removed from array
            if j < len then
               list(j) := list(j + 1);
            end if;
         end loop;

         pnt := pnt - 1;
      end if;
   end delete_from_list;

   function length_of_list return Integer is begin   --function to determine the current number of integers in array
      for i in 1 .. pnt loop
         len := len + 1;
      end loop;
      return len;
   end length_of_list;

   procedure print_list (indx: in Integer) is begin   --procedure that prints the integer at a given index of the array
      Put(list(indx));
      Put(" ");
   end print_list;

   procedure print_list is begin   --procedure that prints the entire array
      for i in 1 .. pnt loop
         Put(list(i));
         Put(" ");
      end loop;
      Put_Line("");
   end print_list;

begin
   pnt := 0;
   len := 0;

end CreateList;

createlist.ads

generic
   max: integer;
   type itemType is private;
   
   with procedure Put(x: itemType);

package CreateList is
      
   procedure add_to_list (listItem: in itemType);
   --   
   procedure delete_from_list (indx: in Integer);
   --   
   function length_of_list return Integer;
   --
   procedure print_list (indx: in Integer);
   procedure print_list;

end CreateList;

谢谢@thindil。 我将get(fVal)更改为FloatIO.get(fVal),它可以正常工作。

解决方法

收到此消息的原因是,您有两个软件包为 Float 提供了 put

  • 您的名为 FloatIO

    Ada.Text_IO.Float_IO(Float)的实例化
  • 用于float的标准软件包,名为 Ada.Float_Text_IO

根据您的需要,您可以同时使用和前缀,也可以仅使用 Ada.Float_Text_IO ,因为您没有特定的浮点类型。

在错误消息中不太容易看到这些:

main.adb:23:40: warning: "max" may be referenced before it has a value
main.adb:61:10: ambiguous expression (cannot resolve "Get")
main.adb:61:10: possible interpretation at a-tiflio.ads:57,instance at line 9
main.adb:61:10: possible interpretation at a-tiflio.ads:57,instance at a-flteio.ads:20
gnatmake: "main.adb" compilation error

唯一的线索是最后一行表明该解释来自 a-flteio.ads 中第20行的实例,该实例是 Ada.Float_Text_IO 的文件名。

请注意,即使 Ada.Float_Text_IO 是类似于您的实例化(即新的Ada.Text_IO.Float_IO(Float)),它也不是相同的包从编译器的角度来看。

,

此错误意味着编译器找到了对所选子程序的一些引用(在您的情况下为get),由于它们看起来都是有效的,因此无法决定应使用哪个子程序。在这种情况下,您必须通过添加正确的程序包名称来准确地告诉编译器您要使用哪一个。在您的情况下,它将是:

get(max);应替换为IntIO.get(max);

get(val);应替换为IntIO.get(val);

get(fVal);应替换为FloatIO.get(fVal);

可能就是所有:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-