-2
我得到一個編譯錯誤,當我嘗試編譯此泛型繼承編譯錯誤
類型「WpfApplication2.CommandInstrumentTrade」不能在泛型類型或方法「作爲類型參數「T」 WpfApplication2.GenericWindowBase 」。有一個從「WpfApplication2.CommandInstrumentTrade」到「WpfApplication2.GenericCommandBase」
public interface IBaseClass
{
int ID { get; set; }
}
public class BaseClass : IBaseClass
{
public int ID { get; set; }
}
public class DerivedClass : BaseClass
{
}
public class Command
{
}
public class GenericCommandBase<T> : Command where T : IBaseClass
{
}
public class DerivedGenericCommand : GenericCommandBase<DerivedClass>
{
}
public class GenericWindowBase<T> where T : GenericCommandBase<IBaseClass>
{
}
public class DerivedGenericWindow : GenericWindowBase<DerivedGenericCommand> // this line fails
{
}
錯誤與您的示例代碼不匹配。該錯誤表示您正在使用'GenericWindowBase',由於'CommandInstrumentTrade'不符合'GenericWindowBase'的where條件而失敗。 –
Peter
繼承不構成泛型。僅僅因爲'Base'和'Derived'具有繼承關係並不意味着'Generic '和'Generic '具有。 –
@Damien_The_Unbeliever你是對的,但是有解決方法嗎? –