📄 accesstypes.adb
字号:
package body AccessTypes isprocedure Init is Cell : Game_Cell := Abyss; begin for Neighbor_Idx in Cell.Neighbor_Count'Range loop Cell.Total_Neighbor_Count := Cell.Total_Neighbor_Count + Cell.Neighbor_Count(Neighbor_Idx).all; end loop; Live_Access.Life_Count := 1; -- ACT access to constant type -- can access to different objects of the defined type -- but cannot change them -- ACT := NWCell'Access; -- -- CAT can only access to object its initialized with. CAT.Life_Count := 1; -- Can access the object it's initialized with -- Cannot access the objects other then its initialized with -- ERROR : left hand side of assignment must be a variable -- CAT := NWCell'Access; end Init;function MyProc(CATP: access constant Game_Cell; ACTP: access constant Game_Cell) return not null Game_Cell_Ptr is R: Game_Cell_Ptr; begin R := new Game_Cell'(Abyss); R.Total_Neighbor_Count := CATP.Total_Neighbor_Count; return R; end MyProc; procedure AccessNotAllowed is type AI is access all Integer; Ref1: AI; begin declare Ref2: AI; I: aliased Integer; begin -- Assignment not allowe because using Ref1 := Ref2 -- would refer to I out of it's life. -- Ref2 := I'Access; -- Ref1 := Ref2; I := 1; end; end AccessNotAllowed;---- function CannotAddToList(The_List: access Game_Cell;-- Obj_Ptr: access Game_Cell) return access Game_Cell is-- Local: access Game_Cell := new Game_Cell;-- begin-- Local.Next := The_List;-- return Local;-- end CannotAddToList;-- function AddToList(The_List: access Game_Cell; Obj_Ptr: access constant Game_Cell) return access Game_Cell is begin return Local: access Game_Cell := new Game_Cell do Local.Next := The_List; end return; end AddToList; -- -- ERROR: functions can only have "in" parameters -- -- function InOutParameter(PIO: in out Game_Cell) return Game_Cell is -- begin -- return PIO; -- end InOutParameter;end AccessTypes;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -