title: static member variable when declared private
body: <p>When a static member variable is declared private in a class, how can it be defined? </p>
  
  <p>Suppose i have the following class declaration</p>
  
  <pre><code>class static_demo
  {
     private:
        static int a;
  
     public:
        static int b;
  
        void set(int x, int y)
        {
           a = x;
           b = y;
        }
  
        void show()
        {
           cout &lt;&lt; "a = " &lt;&lt; a &lt;&lt; "\n";
           cout &lt;&lt; "b = " &lt;&lt; b &lt;&lt; "\n";
        }
  };
  </code></pre>
  
  <p>Then the following statement to define <code>a</code> will result in compilation error.</p>
  
  <pre><code>int static_demo::a;
  </code></pre>
  
  <p>So is it possible to have a static data member in the private section of class?</p>
  
  <p><strong>Adding full code as per Greg</strong>,</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class static_demo
  {
     private:
        static int a;
  
     public:
        static int b;
  
        void set(int x, int y)
        {
           a = x;
           b = y;
        }
  };
  
  int static_demo::a;
  int static_demo::b;
  
  int main()
  {
     static_demo::b = 10;
     static_demo::a = 20;
  
     return 0;
  }
  </code></pre>
  
  <p>The compilation error is:</p>
  
  <pre><code>static_member_variable.cpp: In function `int main()':
  static_member_variable.cpp:20: error: `int static_demo::a' is private
  static_member_variable.cpp:26: error: within this context
  </code></pre>