簡體   English   中英

在Eiffel中收到錯誤“ VEVI:變量未正確設置”

[英]Getting the error “VEVI: Variable is not properly set” in Eiffel

我正在嘗試為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

如果不看ITERATOR類,很難說出真正原因是什么。 這是我的猜測:

ITERATOR類聲明附加類型的屬性target 必須在創建過程中設置屬性。 很可能您需要丟棄類中的屬性collection ,而改用target 根據屬性的類型,您可能需要在類中重新定義它。

在工作方面,最好從一開始就從類的void安全版本開始,並且當您從非void安全的設置切換到void安全的設置時,可能需要確保通過以下方式附加類類型默認值(在項目設置對話框中查找配置選項“默認情況下是否添加類型?” )。 此選項應設置為True (在16.11之前的EiffelStudio中不會自動完成此操作)。

關於代碼其他部分的一些注釋:

  • 如果附加了參數類型,則不會以arg /= Void的形式進行檢查。

  • 如果在父類中為某個功能指定了前提條件foo則無需重復該操作,例如

     require else foo 

    可以安全地將其刪除。 (您可以查看特征平面(或平面短)形式,以了解父項的前提仍然存在。)

  • 如果重新定義功能的注釋未更改,則可以將其替換為

     -- <Precursor> 

    這樣,對父版本的任何更改都會自動反映在重新聲明中(再次查看平面表單)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM