[英]Ada Actual for this must be a variable in out mode
我正在Ada中為“數據結構和算法”類編寫程序。
我當前的問題是“為此”的實際值必須是一個變量”的錯誤,我環顧了一下,並了解到它是由於處於out模式,但是我不完全理解為什么它會在我身上發生。
我看到的示例很有意義,但是我想因為這是我的編碼,所以我只是看不到它?
Procedure AddUnmarked(g:Grid; this:Linked_List_Coord.List_Type; c:Cell) is
cNorth : Cell := getCell(g, North(c));
cEast : Cell := getCell(g, East(c));
cSouth : Cell := getCell(g, South(c));
cWest : Cell := getCell(g, West(c));
Begin
if CellExists(g, cNorth) and not cNorth.IsMarked then
Linked_List_Coord.Append(this, cNorth.Coords);
elsif CellExists(g, cEast) and not cEast.IsMarked then
Linked_List_Coord.Append(this, cEast.Coords);
elsif CellExists(g, cSouth) and not cSouth.IsMarked then
Linked_List_Coord.Append(this, cSouth.Coords);
elsif CellExists(g, cWest) and not cWest.IsMarked then
Linked_List_Coord.Append(this, cWest.Coords);
end if;
End AddUnmarked;
在“ this”傳遞給函數之前,它是我自定義類型Coord(2個整數)的Linked_List。 它已初始化,並且在將列表傳遞到我的代碼中的上述函數之前,已添加了一個坐標對。
這意味着除非您將其作為可修改參數(即in out
傳遞,否則無法修改列表。
詳細地說,認為LIST_TYPE
是標記類型對象的句柄; 為了確保LIST_TYPE
有效,您需要通過in
參數(或創建/操作本地對象)將其傳遞,但是要傳遞結果,則需要out
參數。
因此,為了對已經存在的對象進行操作(並返回結果),您需要in out
。
在Ada中,子例程參數都具有與之關聯的使用模式。 可用的模式為in
, out
和in out
*。 如果未指定模式(例如您未在代碼中指定),則默認為in
。
這些模式指定您可以在子程序內部使用該參數執行的操作。 如果要讀取從例程外部傳入的值,則該值必須包含in
例程in
。 如果你想寫入參數(和/或可能有它讀程序之外),那么它必須有out
就可以了。
由於您的參數都out
,因此您無法寫入任何參數。
(*-還有另一種可能的模式: access
,但這是高級主題)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.