在Eiffel中获取错误“VEVI:变量未正确设置”

时间:2016-07-13 01:19:41

标签: iterator void notnull eiffel

我正在尝试为Eiffel中的linked_list创建一个迭代器。

我收到此错误:未正确设置变量。

Class: ITERATOR_ON_COLLECTION [E]
Feature: make
Attribute(s): {ITERATOR}.target
Line: 30

我知道这是因为无效安全,但我不知道如何解决它。 (我将void安全性设置为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

1 个答案:

答案 0 :(得分:1)

如果不看课程ITERATOR,很难说真正的原因是什么。以下是我猜测会发生什么:

ITERATOR声明附加类型的属性target。必须在创建过程中设置该属性。您很可能需要放弃班级中的collection属性,而是使用target。根据属性的类型,您可能需要在课堂上重新定义它。

就努力而言,从一开始就从类的无效安全版本开始,当你从非虚拟安全设置切换到无效安全设置时,你可能需要确保默认情况下附加类类型(查找配置选项"默认情况下是否附加了类型?" 在项目设置对话框中)。此选项应设置为 True (这不是在16.11之前的EiffelStudio中自动完成的。)

关于代码其他部分的一些评论:

  • 如果附加了参数类型,则arg /= Void形式中没有检查点。

  • 如果为父类中的要素指定了前提条件foo,则无需像

    那样重复它
    require else
        foo
    

    可以安全地删除它。 (您可以查看功能平面(或平坦的短)表格,看看父母的前提是否仍在那里。)

  • 如果未更改重新定义的要素的注释,则可以将其替换为

    -- <Precursor>
    

    这样,父版本中的任何更改都会自动反映在重新声明中(再次查看平面形式)。