Nemo
Nemo

Reputation: 4741

No implicit reference conversion error

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 parameterT' in the generic type or method Heap.PQueue<T>'. There is no implicit reference conversion fromHeap.CustomObject' to `System.IComparable' (CS0311) (Heap)

Upvotes: 1

Views: 4468

Answers (1)

Joel Martinez
Joel Martinez

Reputation: 47809

Your generic constraint is requiring IComparable<T>, but your CustomObject only implements IComparable. You need to implement IComparable<CustomObject>

Upvotes: 6

Related Questions