我正在Ada for Data Structures and Algorithms类中创建一个程序.
我当前的问题是错误'实际'这个"必须是一个变量" 我做了一些环顾四周,我读到它是因为在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;
Run Code Online (Sandbox Code Playgroud)
在"this"传递给函数之前,它是我自定义类型Coord的Linked_List(2个整数).它被初始化并在列表传递给我的代码中的上述函数之前添加了一个坐标对.
这意味着除非您将列表作为可修改的参数传递,否则无法修改列表,即in out.
详细说明,将其LIST_TYPE视为标记类型对象的句柄; 为了确保LIST_TYPE有效,您需要通过in参数传递(或创建/操作本地对象),但要传递结果,您需要一个out参数.
因此,为了对已经存在的对象进行操作{并获得结果},您需要in out.