0

What exactly is this error message complaining about?

I'm trying to create a node class that can hold a value and point to other nodes, as well as be expanded to have more information embedded inside each of the nodes. The recursive templates are giving me some issues though.

public class ColoredNode<T> : Node<ColoredNode<T>, T>
    where T : IComparable
{
    public ConsoleColor Color; 
}

public class BaseNode<T> : Node<BaseNode<T>, T>
    where T : IComparable
{
}

abstract public class Node<N, T>
    where N : Node<N, T>, new()
    where T : IComparable
{
    public N Parent;
    public N Child;
    public T Value;
}

GenericArguments[1], 'T', on 'Node`2[N,T]' violates the constraint of type parameter 'T'.

Curtor
  • 737
  • 2
  • 9
  • 17
  • I actually don't see anything wrong with this code. Is the error complaining about something here? Or is it when you instantiate it in a different part of the code? – Melvin DVaz Aug 31 '13 at 05:20
  • Maybe if you reveal your `BinaryNode` class definition you can be helped. – Timothy Shields Aug 31 '13 at 06:45
  • @TimothyShields I renamed everything from BinaryNode to just Node to make the questiong more simple. All of the code is present. – Curtor Sep 01 '13 at 04:30

1 Answers1

0

I managed to get a repro case as simple as:

public class Node<T> : Node<Node<T>, T>
    where T : IComparable
{
}

abstract public class Node<N, T>
    where N : Node<N, T>, new()
    where T : IComparable
{
}

I noticed that the error message that was being thrown though was in my test cs project, and not the cs project that the Node class was in. However, there was no line or file associated with the error. If I excluded my test project from the solution though, the solution built successfully.

I don't know why this was the case, but I finally tried excluding the test project's automatically generated folder "Test References", which had a DataStructures.accessor file in it. Excluding the file seemed to fix the issue.

Curtor
  • 737
  • 2
  • 9
  • 17