2016-07-13 15 views
0

Eiffelのlinked_listのイテレータを作成しようとしています。エッフェルで「VEVI:変数が正しく設定されていません」エラー

このエラーが発生します:変数が正しく設定されていません。

ボイドの安全性のためですが、私はそれを修正する方法がわかりません。 (私は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 

答えて

0

クラスITERATORを見もせず、それが何であるかを伝えるのは難しいです本当の原因。私の推測はどうなりますか:

クラスITERATORは、添付のタイプの属性targetを宣言しています。属性は、作成手順で設定する必要があります。ほとんどの場合、クラス内の属性collectionを破棄し、代わりにtargetを使用する必要があります。属性のタイプによっては、クラス内で再定義する必要があるかもしれません。

努力の点では、最初からクラスのボイドセーフバージョンから開始することをお勧めします。ボイドセーフな設定からボイドセーフな設定に切り替えるときは、クラスタイプはデフォルトで添付されています(設定オプションを参照)。デフォルトではタイプが添付されていますか?プロジェクト設定ダイアログの)。このオプションはTrueに設定する必要があります(これは16.11より前のEiffelStudioでは自動的に行われません)。

コードの他の部分にいくつかのコメント:

  • 引数型が接続されている場合形態arg /= Voidにおけるチェックのない点がありません。前提条件fooは、親クラスの機能のために指定されている場合は

  • それを安全に取り外すことができる

    require else 
        foo 
    

    のようにそれを繰り返す必要はありません。再定義機能のコメントが変更されていない場合は(あなたが親の前提条件がまだそこにあることを確認するために機能のフラット(またはフラット短い)の形で見ることができます。)

  • 、彼らは

    -- <Precursor> 
    
    に置き換えることができます

    このようにして、親のバージョンの変更は自動的に再宣言に反映されます(再び平面フォームが表示されます)。

+0

ありがとうございました –

関連する問題