-1

I try compile this code:

TMyClass<T: class, constructor> = class(TObjectList<T>)
public
  constructor Create; reintroduce;
end;
TConcretClass = class(TMyClass<TConcretClass>)
public
  constructor Create; reintroduce;
end;

But I get next error:

E2513 Type parameter 'T' must have one public parameterless constructor named Create
Andrey K
  • 1
  • 1

1 Answers1

1
TConcretClass = class(TMyClass<TConcretClass>)

I don't think you mean for the class you are declaring to be a list containing members whose type are itself. In any case, the compiler is objecting because TObjectList<T> has a constructor with parameters that cannot be hidden. The compiler says:

E2513 Type parameter 'T' must have one public parameterless constructor named Create

And TObjectList<T> cannot meet that requirement.

I suspect you want something more like this:

type
  TMyClass<T: class, constructor> = class(TObjectList<T>)
  end;

  TListMemberClass = class(TObject)
  end;

  TConcreteClass = class(TMyClass<TListMemberClass>)
  end;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • OK. I've explained why the compiler reports that error, as you asked. Do you understand why it does so? – David Heffernan Jul 16 '15 at 15:43
  • Ok, Why don't compile this code: TNode = class public constructor Create; end; TConcretNode = class(TNode) public constructor Create; end; TConcretNode have only one public parameterless constructor named Create – Andrey K Jul 17 '15 at 11:28
  • In that case the definition of `TConcretNode` is not complete, and the compiler does not know that `TConcretNode` has the necessary qualities. – David Heffernan Jul 17 '15 at 11:48
  • Do you need any more help with the question that you asked? – David Heffernan Jul 17 '15 at 12:03