title: Two template classes being composed of a member of each other
body: <p>I have a need in my code for two template classes to be composed of a member field of each other. For example, I have two files,</p>
  
  <p>templates.h</p>
  
  <pre><code>template &lt;class T&gt; class B;
  
  template &lt;class T&gt;
  class A
  {
      B&lt;A&gt; a;
  
      // fields and methods dependent on T
  };
  
  template &lt;class T&gt;
  class B
  {
      A&lt;B&gt; b;
  
      // fields and methods dependent on T
  };
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "templates.h"
  
  int main()
  {
      A&lt;int&gt; a;
  }
  </code></pre>
  
  <p>When I compile I receive the output shown in this link</p>
  
  <p><a href="http://pastebin.com/taBWZjar" rel="nofollow">http://pastebin.com/taBWZjar</a></p>
  
  <p>I am using the g++ compiler. When I type g++ --version, I get </p>
  
  <blockquote>
    <p>g++ (Gentoo 4.7.2 p1.3, pie-0.5.5) 4.7.2</p>
  </blockquote>
  
  <p>If this is not possible to do in c++, what is an alternative or work around? Or perhaps is this a bug with my compiler?</p>