2

次のコードがあり、最初の2つのケースだけで共通のプロパティを共有したいと思います。ただし、次の"id" conflicts with the declaration at line 11構文を使用しようとするとエラーが発生します。

   type Shape (Which : Shape_Type := SQUARE) is
      record
      case Which is
         when Square =>
            id : Natural;   -- Line 11
         when Turnout =>
            id : Natural;   -- Line that causes error to be thrown
         when Invalid =>
            null;
      end case;
      end record;
4

1 に答える 1

5

これ:

type Shape (Which : Shape_Type := SQUARE) is
   record
      case Which is
         when Square | Turnout =>
            id : Natural;
         when Invalid =>
            null;
      end case;
   end record;

後でTurnoutケースに追加の属性が必要な場合は、ネストされた を使用してそれを行うことができますcase(ただし、すべての選択肢をカバーする必要があります)。

type Shape (Which : Shape_Type := SQUARE) is
   record
      case Which is
         when Square | Turnout =>
            id : Natural;
            case Which is
               when Square =>
                  null;
               when Turnout =>
                  Deg : Natural;
               when Invalid =>
                  null;
            end case;
         when Invalid =>
            null;
      end case;
   end record;
于 2012-10-06T19:32:20.860 に答える