Given the following declarations :
type Food_T is abstract tagged null record;
type Food_Ptr is access all Food_T'Class;
type Wrapper_T is new Ada.Finalization.Controlled with record
Ptr : Food_Ptr;
end record;
procedure Adjust (Object : in out Wrapper_T) is
begin
null; -- what goes here ?
end Adjust;
I am wondering how to allocate & assign (Deep Copy) the correct derivitive of food_t when i dont know what type Object.ptr will be pointing to (and where Source & Destination are!).
Any help would be appreciated.
Thanks,
NWS.
I think you mean:
procedure Adjust (Object : in out Wrapper_T) is
begin
Object.Ptr := new Food_T'Class'(Object.Ptr.all);
end Adjust;
Then it's Object.Ptr.all's job to ensure that it is really a deep copy, of course. (To do this, Object.Ptr.all's type might want to derive Ada.Finalization.Controlled. To allow this, you might want to make Food_T an interface so that a Food_T-deriving type can also derive from Ada.Finalization.Controlled.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With