with Ada.text_IO; use Ada.Text_IO;
with Ada.Tags; use Ada.Tags;
procedure Tag_Main is
package foo is
type A is tagged private;
type B is tagged private;
private
type A is tagged null record;
type B is tagged null record;
end foo;
use Foo;
function Tag_To_String(From : Ada.Tags.Tag) return String is(
if From = A'Tag then
"This is tag A"
else
"This is tag B"
);
begin
Put_Line(Tag_To_String(A'Tag));
Put_Line(Tag_To_String(B'Tag));
end Tag_Main;
注意,我已经编辑了使用函数表达式的代码。它仍然适用于GNAT/GPS 2018版本。
这个版本是用gprbuild-d-PD编译的