Reputation: 4741
I am getting the following error when using a CustomObject to instantiate my generic priority queue. It is working well when I instantiate with integer. Can anyone help me figure out the issue.
The error is appearing on line:
PQueue<CustomObject> pq = new PQueue<CustomObject>();
Error CS0311: The type
Heap.CustomObject' cannot be used as type parameter
T' in the generic type or methodHeap.PQueue<T>'. There is no implicit reference conversion from
Heap.CustomObject' to `System.IComparable' (CS0311) (Heap)
Upvotes: 1
Views: 4468
Reputation: 47809
Your generic constraint is requiring IComparable<T>
, but your CustomObject
only implements IComparable
. You need to implement IComparable<CustomObject>
Upvotes: 6