title: Static vs. member variable
body: <p>For debugging, I would like to add some counter variables to my class. But it would be nice to do it without changing the header to cause much recompiling.</p>
  
  <p>If Ive understood the keyword correctly, the following two snippets would be quite identical. Assuming of course that there is only one instance.</p>
  
  <pre><code>class FooA
  {
  public:
      FooA() : count(0) {}
      ~FooA() {}
  
      void update()
      {
          ++count;
      }
  
  private:
      int count;
  };
  </code></pre>
  
  <p>vs.</p>
  
  <pre><code>class FooB
  {
  public:
      FooB() {}
      ~FooB() {}
  
      void update()
      {
          static int count = 0;
          ++count;
      }
  };
  </code></pre>
  
  <p>In <strong>FooA</strong>, count can be accessed anywhere within the class, and also bloats the header, as the variable <em>should</em> be removed when not needed anymore.</p>
  
  <p>In <strong>FooB</strong>, the variable is only visible within the one function where it exists. Easy to remove later. The only drawback I can think of is the fact that FooB's count is shared among all instances of the class, but thats not a problem in my case. </p>
  
  <ul>
  <li>Is this correct use of the keyword? I assume that once <strong>count</strong> is created in <strong>FooB</strong>, it stays created and is not re-initialized to zero every call to update.</li>
  <li>Are there any other caveats or headsup I should be aware of?</li>
  </ul>
  
  <p><strong>Edit:</strong> After being notified that this would cause problems in multithreaded environments, I clarify that my codebase is singlethreaded.</p>