ChuckJ's Blog Please read my disclaimer. It is better to be silent and thought a fool, than to speak and remove all doubt." -- Silvan Engel

...Removing All Doubt

Chuck Jazdzewski

Linked List VI: Recursion - see recursion

I finally have a definitive answer to the question of why MyNode is needed. Consider the following, simplified, version of the LinkedList classes I posed,

  class C<X> { class N { } }
  class D: C<D.N> { }

This is really an obfuscated form of

  class N<X> { }
  class C<X> { }
  class D: C<N<?>> { }

where ? needs to be replaced by an infinite list if N<N<...>>. In other words, I am trying to define a type directly in terms of itself, a T where T=N<T>. This is not allowed. An additional type is required to break the cycle, such as M in,

  class M: N<M> { }

Then I can write,

  class D: C<M> { }

So, there we have it, MyNode is necessary to avoid defining a type directly in terms of itself. The unobfuscated version makes this much more clear. MyNode serves the same role as M does above.

Thanks again to Andrew for taking the time to beat this into my thick skull.

09/25/2006 10:06 AM | Comments [1] | #Programming

Content © 2008 Chuck Jazdzewski | Subscribe to my RSS feed.

All source code above is usable under the Microsoft Permissive License (Ms-PL) unless otherwise specified in the containing entry.

Powered by BlogX