title: incrementing static member of a class in main - C++
body: <p>I am getting this error <code>error: expected unqualified-id before ‘++’ token 29 | std::cout&lt;&lt;x::foo::++z;</code></p>
  <p>basically I am trying to increment <code>z</code> from foo in main</p>
  <pre><code>#include &lt;iostream&gt;
  
  namespace x {
    class foo {
    public:
      void bar1(foo&amp; f) {
        ++x;     
      }
      friend void bar2(foo&amp; f);
  
      int x;
      int y;
      static  int z;
    };
  
    int x::foo::z=15;
    void bar2(foo&amp; f) {
      f.y++;       // Error: y not in scope
    }
  }
  
  int main() {
    x::foo a;
    ++a.x=5;
    std::cout &lt;&lt; ++a.x &lt;&lt; std::endl;
    std::cout &lt;&lt; x::foo::z;
    std::cout &lt;&lt; x::foo::++z; //throws error
    return 0;
  }
  </code></pre>
  <p>z is static member.</p>
  <p>my question is how to access and increment static member <code>z</code>?
  also can declaration be done outside class in C++, somehow?</p>