简体   繁体   中英

declaring a generic type “of a generic type”

Not exactly sure how to pose this question, but using lazarus v1.8.2 I am attempting to define a generic type, using another generic type:

//initial interface
  IOtherInterface<T> = interface
    function ExampleFunction : T;
  end;
  //some generic record
  TSomething<T> = record
    Something : T;
  end;
 //attempting to further genericize
  IOtherSomething<T> = IOtherInterface<TSomething<T>>;

The error I receive is: Fatal: Syntax error, "," expected but "<" found

I'm using mode delphi as I want to remain compliant for both compilers. I feel pretty confident that I've done this sort of specialization in delphi before, but don't have great access to a professional version to test. Is this a limitation to on FPC side of things, or perhaps am I missing something? Any help is greatly appreciated

I am not sure what

 IOtherSomething<T> = IOtherInterface<TSomething<T>>;

is meant to achieve here. If you are trying to extend the interface you need something like

IOtherSomething<T> = interface(IOtherInterface<TSomething<T>>)
end;

which does compile in Delphi. I don't have Lazarus to test.

If this is not what you are trying to do I will delete the answer.

If it is, I will edit to remove these comments.

Afaik you should still declare IOtherInterface and later specialize it with TSomething .

Generics.Collections works this way (with TPair in the role of TSomething ).

Anyway, FPC fixes has a problem with double specializations, it sees >> or << as shift tokens. This is fixed in trunk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM