Eiffel 继承和游标使用[无法编译]
Eiffel inheritance and cursor usage [can't compile]
我有以下测试用例:
test_different_cursor: BOOLEAN
local
cursor: SET_ITERATION_CURSOR[INTEGER, INTEGER]
sets: ARRAY[SET[INTEGER, INTEGER]]
do
create sets.make_empty
check attached {SET_ITERATION_CURSOR[INTEGER, INTEGER]} d.different_cursor as current_cursor then
cursor := current_cursor
end
from
until
cursor.after
loop
sets.force (cursor.item, sets.count + 1)
cursor.forth
end
end
在这里,在 from~end 的循环中,我尝试调用 Array class 的 force 功能,但是编译器一直提示该行出现以下错误:
Error code: VUAR(2)
Type error: non-compatible actual argument in feature call.
What to do: make sure that type of actual argument is compatible with
the type of corresponding formal argument.
Class: MY_TESTS
Feature: test_different_cursor
Called feature: force (v: [like item] G; i: INTEGER_32) from ARRAY
Argument name: v
Argument position: 1
Formal argument type: SET [INTEGER_32, INTEGER_32]
Actual argument type: TUPLE [INTEGER_32, INTEGER_32]
Line: 193
loop
-> sets.force (cursor.item, sets.count + 1)
cursor.forth
在这种情况下,似乎我需要制作继承 ARRAY class 的 SET class 并在那里重新定义强制功能。但我不太确定这是修复编译错误的正确方法。这是我的 SET class 的样子:
class
SET[A, B]
create
make
feature
valueA: A
valueB: B
feature
make (first: A; second: B)
do
valueA := first
valueB := second
end
end
我需要做什么才能解决这个问题?
cursor.item
返回的值需要转换为SET [INTEGER, INTEGER]
。这可以通过添加局部变量
来完成
t: TUPLE [first: INTEGER; second: INTEGER]
到功能 test_different_cursor
并更改行
sets.force (cursor.item, sets.count + 1)
进入
t := cursor.item
sets.force (create {SET [INTEGER, INTEGER]}.make (t.first, t.second), sets.count + 1)
我有以下测试用例:
test_different_cursor: BOOLEAN
local
cursor: SET_ITERATION_CURSOR[INTEGER, INTEGER]
sets: ARRAY[SET[INTEGER, INTEGER]]
do
create sets.make_empty
check attached {SET_ITERATION_CURSOR[INTEGER, INTEGER]} d.different_cursor as current_cursor then
cursor := current_cursor
end
from
until
cursor.after
loop
sets.force (cursor.item, sets.count + 1)
cursor.forth
end
end
在这里,在 from~end 的循环中,我尝试调用 Array class 的 force 功能,但是编译器一直提示该行出现以下错误:
Error code: VUAR(2)
Type error: non-compatible actual argument in feature call.
What to do: make sure that type of actual argument is compatible with
the type of corresponding formal argument.
Class: MY_TESTS
Feature: test_different_cursor
Called feature: force (v: [like item] G; i: INTEGER_32) from ARRAY
Argument name: v
Argument position: 1
Formal argument type: SET [INTEGER_32, INTEGER_32]
Actual argument type: TUPLE [INTEGER_32, INTEGER_32]
Line: 193
loop
-> sets.force (cursor.item, sets.count + 1)
cursor.forth
在这种情况下,似乎我需要制作继承 ARRAY class 的 SET class 并在那里重新定义强制功能。但我不太确定这是修复编译错误的正确方法。这是我的 SET class 的样子:
class
SET[A, B]
create
make
feature
valueA: A
valueB: B
feature
make (first: A; second: B)
do
valueA := first
valueB := second
end
end
我需要做什么才能解决这个问题?
cursor.item
返回的值需要转换为SET [INTEGER, INTEGER]
。这可以通过添加局部变量
t: TUPLE [first: INTEGER; second: INTEGER]
到功能 test_different_cursor
并更改行
sets.force (cursor.item, sets.count + 1)
进入
t := cursor.item
sets.force (create {SET [INTEGER, INTEGER]}.make (t.first, t.second), sets.count + 1)