title: C++ declaring a static object in a class
body: <p>I'm trying to declare a static object of a class A that I wrote in a different class B, like this:</p>
  
  <pre><code>class A // just an example
  {
      int x;
  public:
      A(){ x = 4; }
      int getX() { return x; }
  };
  
  class B
  {
      static A obj1;  // &lt;- Problem happens here
  public:
      static void start();
  };
  
  int main()
  {
      B::start();
  }
  
  void B::start()
  {
      int x = obj1.getX();
  }
  </code></pre>
  
  <p>What I want to achieve is to get <code>int x</code> in <code>B::start()</code> to equal <code>int x</code> in <code>class A</code> (4).</p>
  
  <p>I tried googling all this for the past hour and all I understood was that C++ doesn't allow static objects' declarations. Is that correct?</p>
  
  <p>If so, here's my question. How can I get the same result? What are my available workarounds? Keeping in mind that the rest of my code depends on the functions in class B to be static.</p>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>error LNK2001: unresolved external symbol "private: static class A B::obj1"</p>
  </blockquote>
  
  <p>Thanks!</p>