title: Delphi generic nested classes
body: <p>I was doing a comparison between C++ and Delphi and I found something tricky to me.</p>
  
  <p>This is very easy C++ code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  class C {
  
   class D {
    T x;
   }
  
  }
  </code></pre>
  
  <p>In this scenario, we have that the class <code>C</code> is a template class ( = generic class) and the nested class <code>D</code> is also a template class. If <code>T</code> is a <code>double</code>, the <code>x</code> inside <code>D</code> is <code>double</code>.</p>
  
  <p>I cannot say this:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  class C {
  
   template&lt;typename T&gt;
   class D {
    T x;
   }
  
  }
  </code></pre>
  
  <p>That is an error since I am already "inside" <code>C</code> and another <code>T</code> would be a conflict. To fix the error, I should use a different name, like <code>U</code>.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  class C {
  
   template&lt;typename U&gt;
   class D {
    T x;
   }
  
  }
  </code></pre>
  
  <p>In Delphi, I could write this:</p>
  
  <pre class="lang-pascal prettyprint-override"><code>type
   TClassC&lt;T&gt; = class
    private
  
     type
      TClassD = class
       private 
        x: T;
      end;
  
   end;
  </code></pre>
  
  <p>If <code>T</code> is an <code>integer</code>, now <code>x</code> is an <code>integer</code> since (from what I've understood reading online) the <code>TClassD</code> is <code>integer</code>. In Delphi this is also legal:</p>
  
  <pre class="lang-pascal prettyprint-override"><code>type
   TClassC&lt;T&gt; = class
    private
  
     type
      TClassD&lt;T&gt; = class // &lt;-- note the &lt;T&gt; repeated!!
       private 
        x: T;
      end;
  
   end;
  </code></pre>
  
  <p>What about now? If I am able to declare <code>T</code> again in <code>TClassD</code>, this means that without the <code>&lt;T&gt;</code> I'd have a non-generic <code>TClassD</code> class.  Am I correct?</p>