why do I get a compiler error in the following code stating: Cannot implicty convert type SpecialNode to T
even though T must derive from NodeBase as I defined
The problem is that the function may be called with a type parameter T
, which derives from NodeBase
but not from SpecialNode
. The compiler doesn't check the semantics of the if
statement, so it doesn't know, that T has to be a specialNode
.
You would need to use an explicit cast to T
in order to satisfy your compiler.