Ada:“image”属性的前缀必须是一个类型

时间:2012-10-01 01:41:11

标签: ada

我正在尝试使用Ada打印一个源自Natural的类;但是,我一直收到错误prefix of "image" attribute must be a type。谷歌显然对此错误一无所知。

以下是产生此错误的简化代码:

with Ada.Text_IO;
use Ada.Text_IO;
with Layout; use Layout;
procedure temptest is
   term : Terminator_ID;
   begin
      term := Layout.Block_GetOpposite (1, Layout.REVERSED);
   Put_Line (Item => term'Image);
   end temptest;

以下是Terminator_ID包中Layout的定义:type Terminator_ID is new Natural range 1 .. 40;

导致此错误的原因是什么,以及纠正错误的适当方法是什么?

1 个答案:

答案 0 :(得分:4)

显然,将数字转换为字符串的语法是Type_Name'Image(var_containing_value)

我将代码更改为:

with Ada.Text_IO;
use Ada.Text_IO;
with Layout; use Layout;
procedure temptest is
   term : Terminator_ID;
   begin
      term := Layout.Block_GetOpposite (1, Layout.REVERSED);
   Put_Line (Item => Terminator_ID'Image (term));
   end temptest;

现在编译得很好。

相关问题