given this two classes, a heap of objects, visual studio tells me that the class "Uccellino" has not property "number", how can I solve this? Thanks in advance to who will help me.
Minheap Class:
public class MinHeap<Uccellino>
{
Uccellino[] heap;
int capacity;
int occupied;
//[...]
public Uccellino Parent(int index)
{
return heap[(index - 1) / 2];
}
public void Inserisci( Uccellino u)
{
heap[occupied] = u;
int i = occupied;
occupied++;
while (i != 0 && ((Uccellino)Parent(i)).number > ((Uccellino)heap[i]).number) //it gives me error in this line
{
Uccellino temp = heap[i];
heap[i] = Parent(i);
heap[(i - 1) / 2] = temp;
i = (i - 1) / 2;
}
}
}
Uccellino class:
public class Uccellino
{
public int id { get; }
public int number { get; }
public Uccellino(int identifier, int num)
{
this.id = identifier;
this.number = num;
}
}
>Solution :
public class MinHeap<Uccellino> declares a generic class with generic type parameter with name Uccellino. Either remove it (it seems to not be needed here) or rename it to something like T, otherwise it shadows the Uccellino class:
public class MinHeap
{
// the rest is the same
}
Read more: