title: how global variable differs from class variable, are they the same?
body: <p>Given that a variable declared outside a function is a global variable.</p>
  
  <pre><code>//sample.cpp
  int g = 0;
  namespace foo 
  {
      int x = 5;
      class bar
      {
          int y = 7;
          /** rest of the bar class **/
      }
      /** rest of the bar namespace **/
  }
  </code></pre>
  
  <p>I understand that g is a global variable.<br>
  My question is:<br>
  is x a global variable?<br>
  is y a global variable?<br>
  in other words: are variables declared(defined in my example) in class and namespace global variables aswell?</p>
  
  <p>added after edit >> whole text that follows.</p>
  
  <p>changed sample.cpp to:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int g;
  int g2 = 2;
  namespace foo 
  {
      extern int x = 5;
      extern int x2; //accessing x2 will lead to an error.
      class bar
      {
        public:
          int foo::bar::y; //declaring y with a value will lead to an error.
          /** rest of the bar class **/
      };
      /** rest of the bar namespace **/
  }
  
  int main()
  {
  
  }
  </code></pre>
  
  <p>As Jon suggested I tried some things out and come to the following assumptions:<br></p>
  
  <ul>
  <li>g is a global variable and is initialized with 0 and is initialized before main().<br></li>
  <li>x is a namespace variable and must be given a declaration and is initialized before main().</li>
  <li>y is a class variable which can not be given a declaration and is not initialized before main() and must be initialized by i.e. a constructor.</li>
  <li>the only global variable is g i guess, since all global int-variables are initialized with the value 0, which is not the case for x and y.</li>
  </ul>