tgeneric113.pp 358 B

1234567891011121314151617181920212223242526
  1. {$Mode ObjFPC}{$H+}
  2. type
  3. TBase = class
  4. public
  5. function Foo:Integer;virtual;abstract;
  6. end;
  7. generic TTest<T:class> = class(T)
  8. public
  9. function Foo:Integer;override;
  10. end;
  11. function TTest.Foo:Integer;
  12. begin
  13. Result:=42;
  14. end;
  15. var
  16. b: TBase;
  17. begin
  18. b:=specialize TTest<TBase>.Create;
  19. if b.Foo<>42 then
  20. Halt(1);
  21. WriteLn('Ok');
  22. end.