title: Access static variable from static function
body: <p>It is very important that my function is static, I need to access and modify another static/non-static class member in order to print it out later. How can I do that?</p>
  
  <h2>Flow</h2>
  
  <ul>
  <li>Class is initiated</li>
  <li>Constructor sets variable to something using internal function that must be static</li>
  <li>Some time later I print that variable</li>
  </ul>
  
  <h2>Example code</h2>
  
  <pre><code>#include &lt;iostream&gt;
  
  class MyClass
  {
  public:
      static int s;
      static void set()
      {
          MyClass::s = 5;
      }
  
      int get()
      {
          return MyClass::s;
      }
  
      MyClass()
      {
          this-&gt;set();
      }
  };
  
  void main()
  {
      auto a = new MyClass();
  
      a-&gt;set(); // Error
  
      std::cout &lt;&lt; a-&gt;get() &lt;&lt; std::endl; // Error
  
      system("pause");
  }
  </code></pre>
  
  <h2>Error</h2>
  
  <pre><code>LNK2001: unresolved external symbol "public: static int MyClass::s" (?s@MyClass@@2HA)
  LNK1120: 1 unresolved externals
  </code></pre>