return - 使用过程类范围的输出参数作为函数返回值
问题描述
type T is abstract tagged null record;
type T1 is new T with null record;
procedure Get_Value (Value : out T'Class) is
T1_Value : T1 := (null record);
begin
Value := T'Class (T1_Value);
end;
function Result return T'Class is
T_Class_Value : T'Class; -- Initialization required
begin
Get_Value (T_Class_Value);
return T_Class_Value;
end Result;
在此代码中,T_Class_Value 需要初始化。如何从 Get_Value 参数初始化 T_Class_Value?
解决方案
with Ada.Text_Io; use ADa.Text_IO;
procedure Main is
type T is abstract tagged null record;
type T1 is new T with null record;
function Result return T1'Class is
T1_Value : t1 := (Null record);
begin
return T1'Class(T1_Value);
end Result;
T1_Class : T1'Class := Result;
begin
Put_Line("It works");
end Main;
推荐阅读
- oauth - OAuth:缩小范围?
- json - 有没有更好的方法将 Rust BSON 文档直接转换为 JSON?
- python - Python3.6:根据列表的给定元素将列表分成子列表
- python - Python 中的 CSV 到 XLSX
- android - 毕加索中的Firebase新版本getDownloadUrl不起作用
- java - Firebase:如何记录读/写错误的完整参考
- amazon-web-services - 如何调试cloudformation模板?策略中的语法错误。YAML 文件
- excel - 在 Excel 中使用文本和值对代码进行排序
- python - Beautiful Soup 找不到我想要的 HTML 部分
- testing - VSTS - 如何获得代码覆盖率结果