David Heffernan
David Heffernan

Reputation: 613572

Why is class of T not allowed in a generic type?

Consider this program:

type
  TMyClass<T: class> = class
  public type
    TClassOfT = class of T;
  end;

begin
end.

This fails to compile at the declaration of TClassOfT with the error message:

E2021 Class type required

Can anyone explain why this is so? If I were to instantiate this class with, for instance TMyClass<TObject> then surely class of TObject would be meaningful. I constrained the generic parameter to be a class. So how can the compiler object that T is not a class type?

Upvotes: 14

Views: 1400

Answers (1)

David Heffernan
David Heffernan

Reputation: 613572

So far as I can tell, there is no reason for the compiler to reject this code. Thus, I believe that it is a design flaw and have submitted QC#121178.

Upvotes: 3

Related Questions