我正在尝试使用 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;
Run Code Online (Sandbox Code Playgroud)
这是Terminator_ID我的Layout包中的定义:type Terminator_ID is new Natural range 1 .. 40;
导致此错误的原因是什么,纠正它的适当方法是什么?
显然,将数字转换为字符串的语法是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;
Run Code Online (Sandbox Code Playgroud)
它现在编译得很好。