私は自分の最大ヒープを展開しています。インターフェイスを拡張するジェネリッククラスを使用すると何か問題があります。ジェネリックスの拡張インターフェイスを使用するクラス
class SuffixOverlap:IComparable<SuffixOverlap>
{
//other code for the class
public int CompareTo(SuffixOverlap other)
{
return SomeProperty.CompareTo(other.SomeProperty);
}
}
そして、私は私のヒープクラスを作成します:
class LiteHeap<T> where T:IComparable
{
T[] HeapArray;
int HeapSize = 0;
public LiteHeap(List<T> vals)
{
HeapArray = new T[vals.Count()];
foreach(var val in vals)
{
insert(val);
}
}
//the usual max heap methods
}
しかし、私はこれを行うにしてみてください。
LiteHeap<SuffixOverlap> olHeap = new LiteHeap<SuffixOverlap>(listOfSuffixOverlaps);
私はエラーを取得する:私はこのようなクラスを持っていると言います The type SuffixOverlap cannot be used as a type parameter T in the generic type or method LiteHeap<T>. There is no implicit reference conversion from SuffixOverlap to System.IComparable.
ジェネリッククラスのT implを使用するクラスとしてLiteHeapを作成するにはどうすればよいですか私はnew LiteHeap<SomeClass>
を書くことができますし、工assがIComparableを
'IComparable'ではない' IComparableを ' –
Mahmoud