简体   繁体   English

声明通用类型为“通用类型”

[英]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: 不完全确定如何提出这个问题,但是我使用lazarus v1.8.2尝试使用另一个泛型类型定义一个泛型类型:

//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 我收到的错误是: Fatal: Syntax error, "," expected but "<" found

I'm using mode delphi as I want to remain compliant for both compilers. 我正在使用模式delphi,因为我希望对两个编译器都保持兼容。 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. 我以前很有信心在delphi中做过这样的专业化工作,但我没有很大的机会来测试专业版本。 Is this a limitation to on FPC side of things, or perhaps am I missing something? 这是对FPC方面的限制,还是我缺少某些东西? 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. 可以在Delphi中编译。 I don't have Lazarus to test. 我没有Lazarus要测试。

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 . Afaik您仍然应该声明IOtherInterface,以后使用TSomething对其进行专门化。

Generics.Collections works this way (with TPair in the role of TSomething ). Generics.Collections以这种方式工作(TPair在TSomething中扮演角色)。

Anyway, FPC fixes has a problem with double specializations, it sees >> or << as shift tokens. 无论如何,FPC修复程序存在双重专业化问题,它将>>或<<视为移位令牌。 This is fixed in trunk 这是固定在行李箱中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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