title: How to forward declare a template class and use it as a member data in C++?
body: <p>I am trying to forward declare a template class then use the class to declare a member data in some other class. The code is below:</p>
  
  <pre><code>using namespace std;
  
  template&lt;class T&gt;
  class B;
  
  class A{
     B&lt;T&gt; b;
  };
  
  template&lt;class T&gt;
  class B{
      T x;
  };
  
  int main(){
  }
  </code></pre>
  
  <p>I got the compilation error:</p>
  
  <pre><code>error: ‘T’ was not declared in this scope
       B&lt;T&gt; b;
  </code></pre>
  
  <p>Can anybody let me know what I did wrong and how to achieve my goal? (I noticed the posts on template class on SO, but none of them answers my question.)</p>
  
  <p>Thanks a lot in advance!</p>