我正在尝试为 Eiffel 中的linked_list 创建一个迭代器。
我收到此错误:变量设置不正确。
Class: ITERATOR_ON_COLLECTION [E]
Feature: make
Attribute(s): {ITERATOR}.target
Line: 30
我知道这是因为虚空安全,但我不知道如何解决它。(我将 void safety 设置为 True 并将预编译库更改为安全版本并 clean_compile 它。)
以下是课程:
class
ITERATOR_ON_COLLECTION [E]
inherit
ITERATOR [E]
create
make
feature {NONE} -- Attributes
collection: LINKED_LIST[E]
item_index: INTEGER
feature -- initialization
make(c: LINKED_LIST [E])
require
--c /= void
do
-- create {COLLECTION} collection.make
-- create collection.make -- it doesnt work with/without this line
collection := c
item_index := 1
end
start
do
item_index := 1
end
item: STRING
do
Result := "hello"
end
next
do
item_index := item_index + 1
end
is_off: BOOLEAN
do
Result := True
end
do_until (action: PROCEDURE [E]; test: FUNCTION [E, BOOLEAN])
-- Apply `action' to every item of `target' up to
-- and including first one satisfying `test'.
-- (Apply to full list if no item satisfies `test').
require else
action_exists: action /= Void
test_exists: test /= Void
do
end
do_while (action: PROCEDURE [E]; test: FUNCTION [E, BOOLEAN])
-- Apply `action' to every item of `target' up to
-- and including first one not satisfying `test'.
-- (Apply to full list if all items satisfy `test').
require else
action_exists: action /= Void
test_exists: test /= Void
do
end
until_do (action: PROCEDURE [E]; test: FUNCTION [E, BOOLEAN])
-- Apply `action' to every item of `target' up to
-- but excluding first one satisfying `test'.
-- (Apply to full list if no items satisfy `test'.)
require else
action_exists: action /= Void
test_exists: test /= Void
do
end
while_do (action: PROCEDURE [E]; test: FUNCTION [E, BOOLEAN])
-- Apply `action' to every item of `target' up to
-- but excluding first one satisfying not `test'.
-- (Apply to full list if all items satisfy `test'.)
require else
action_exists: action /= Void
test_exists: test /= Void
do
end
there_exists (test: FUNCTION [E, BOOLEAN]): BOOLEAN
-- Is `test' true for at least one item of `target'?
require else
test_exists: test /= Void
do
end
for_all (test: FUNCTION [E, BOOLEAN]): BOOLEAN
-- Is `test' true for all items of `target'?
require else
test_exists: test /= Void
do
end
end