コンストラクター関数を介して制限された型を返そうとしています。限定型なので型をコピーできないのは承知していますが、どうしたらいいかわかりません。拡張された return ステートメントを使用して動作させていますが、制限された型をそれなしで返すことができるはずだと言われました。
thing_protected.ads:
package Thing_Protected is
type Thing is protected interface;
procedure Verb_It (Object : in out Thing; Key : String) is abstract;
function Create return Thing'Class;
private
protected type Thing_Impl is new Thing with
overriding procedure Verb_It (Key : String);
private
Data : Integer;
end Thing_Impl;
end Thing_Protected;
thing_protected.adb:
package body Thing_Protected is
function Create return Thing'Class is
begin
-- Not sure how to make this work:
-- return Thing_Impl'(Data=><>, others=><>);
-- thing_protected.adb:6:35: expected type "Thing_Impl" defined at thing_protected.ads:10
-- thing_protected.adb:6:35: found a composite type
-- extended return:
-- return X : Thing_Impl do
-- null;
-- end return;
-- shortened version:
return X : Thing_Impl;
end;
protected body Thing_Impl is
overriding procedure Verb_It (Key : String) is
begin
null;
end;
end Thing_Impl;
end Thing_Protected;
main.adb:
with Thing_Protected;
procedure Main is
Thing_Instance : Thing_Protected.Thing'Class := Thing_Protected.Create;
begin
null;
end;