Why templates must be defined outside class : <p>I know that templates must be declared and defined in the same file. But, why I cannot:</p>

<pre><code>#ifndef guard
#define guard
template&lt;typename T&gt;
class Test{
   void method(){

   }
}; 
#endif
</code></pre>

<p>And it is causes compiler error ( not directly but instatantiation template Test in two different place- for example in main() and as field in any class causes error. </p>

<p>It must be defined outside class ( It doesn't cause error like here)</p>

<pre><code>#ifndef guard
#define guard
template&lt;typename T&gt;
class Test{
   void method();

}; 
#endif
template&lt;typename T&gt;
void Test&lt;T&gt;::method(){}
</code></pre>

<p>Why?</p>
