I want to wrap List
class with my custom class. As for now I have something like this ;
public class PriorityListOfNodes
{
private List<Node> list_;
private IComparer<Node> sorter_;
public List<Node> List_ {
get {return list_;}
set {list_ = value;}
}
public PriorityListOfNodes ()
{
sorter_ = new NodeSorter_fValueDescending ();
}
public Node PopFromEnd ()
{
Node temp = new Node (list_ [list_.Count - 1]);
list_.RemoveAt (list_.Count - 1);
return temp;
}
public Node PeekFromEnd ()
{
return list_ [list_.Count - 1];
}
public void Add (ref Node toAdd)
{
Debug.Log (toAdd);
list_.Add (toAdd);
list_.Sort (sorter_);
}
}
When I do now
Node temp = new Node(10,20); //custom constructor
PriorityListOfNodes l = new PriorityListOfNodes();
l.add(temp);
I get runtime exception :
Object reference not set to an instance of an object
I have also tried without ref
but with the same result. What am I doing wrong here ?
You never actually instantiate a List<Node>
.
public PriorityListOfNodes ()
{
sorter_ = new NodeSorter_fValueDescending ();
list_ = new List<Node>();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With