0
我沿着以下線的東西:指定依賴於其他泛型類通用約束
// This part is fine
abstract class Attack {}
abstract class Unit<A> where A : Attack {}
class InstantAttack : Attack {}
class Infantry : Unit<InstantAttack> {}
// I'm lost here, on this part's syntax:
abstract class Controller<U> where U : Unit {}
// I want the above class to take any kind of Unit, but Unit is a generic class!
以上爲Controller
不起作用,因爲where U : Unit
是不對的,因爲Unit
需要一個通用的參數(如Unit<InstantAttack>
)。我試過了:
abstract class Controller<U<A>> where U<A> : Unit<A> {}
這肯定沒有工作。什麼是正確的語法來做到這一點?
/捂臉。謝謝! – Cornstalks 2013-02-19 03:33:00