title: Using static variable along with templates
body: <p>I have a template class defined in a header file like this. Here I have defined a static variable as well:</p>
  
  <pre><code>#ifndef TEST1_H_
  #define TEST1_H_
  
  void f1();
  
  static int count;
  
  template &lt;class T&gt;
  class MyClass
  {
  public:
  
      void f()
      {
          ++count;
      }
  
  
  };
  
  #endif
  </code></pre>
  
  <p>And I have defined main() function in a different cpp file like this:</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
      MyClass&lt;int&gt; a;
      a.f();
      f1();
  
      cout&lt;&lt;"Main:" &lt;&lt; count &lt;&lt; "\n";
  
      return 0;
  }
  </code></pre>
  
  <p>I have implemented function f1() in a different cpp file like this:</p>
  
  <pre><code>void f1()
  {
      MyClass&lt;int&gt; a;
      a.f();
  
      cout&lt;&lt;"F1: " &lt;&lt;count &lt;&lt;"\n";
  }
  </code></pre>
  
  <p>When I compiled this using VC6, I got the output as "F1:0 Main:2". How is this possible? Also, in general how should I handle if I want to use static variables along with templates?</p>