泛型类型的限制

时间:2015-09-07 07:15:24

标签: delphi generics

此泛型类型的声明将无法编译

type
  TFoo<T> = record
    Value : T;
  end;

  TFooo = TFoo<TFoo<Int64>>; // this is fine
  TFoooooInt64 = TFoo<TFoo<TFoo<Int64>>>; // E2564

因为

  

E2564未定义类型&#39; TFoo<T>&#39;

此错误E2564为documented

  

尝试使用自身在泛型类型上定义类型约束时会发生这种情况。

program E2564;

{$APPTYPE CONSOLE}
type
  TRec<T: record> = record
    A: T;
  end;

  TClass = record
    V: TRec<TClass>; //E2564
  end;

begin
end.

但事实并非如此。

这是一个错误还是记录了这个限制?

0 个答案:

没有答案