这是一个创建于 1741 天前的主题,其中的信息可能已经有所发展或是发生改变。
比如我们有 类 vehicle {速度: int, 价格: int}, boat{速度: int, 价格: int, 排水量:int}, 所以船类是交通工具类的子类
现在有 f ( g: Vehicle → int) = ... g( new(Vehicle)), 意思是函数 f 以 另一个函数 g : Vehicle → int 为参数
1. 请问我可以让 f 以( h: Boat → int) 为参数吗?可以举一个 f 的具体例子吗?
2. 我知道 (Vehicle → int) 是 (Boat → int)的子类,但是我只知道这个是对的,但是理解不了很迷糊,可以解释一下吗?
谢谢!
5 条回复 • 2019-12-15 14:34:02 +08:00
|
|
1
ipwx 2019-12-15 09:48:07 +08:00 via Android
首先,你这啥语言的。不是所有语言都有这种函数子类的概念。然后比如 c++,这里就得用模板函数,加个 enable if,就行了,反正不用搞这种函数子类的问题。
|
|
|
2
trihuan 2019-12-15 09:52:04 +08:00
|
|
|
3
trihuan 2019-12-15 09:52:14 +08:00
|
|
|
4
secondwtq 2019-12-15 13:22:19 +08:00 via iPhone
搜 variance 另外这个不叫”子类”,subtyping 和 inheritance 不一样
|
|
|
5
imn1 2019-12-15 14:34:02 +08:00
我觉得合理的做法是交通工具作为一个抽象类,作为接口
|