title: Why do I get an "undefined reference" link error for a static member variable?
body: <p>I have this code </p>
  
  <p><strong>File:  Gnome.cpp</strong></p>
  
  <pre><code>#include "Living.h"
  
  class Gnome : public Living {
  public:
      Gnome();
      void drawObjects();
  };
  
  
  Gnome::Gnome()
  {
    // **** The line below is where the error occurs **** 
    spriteImg = new Sprite("graphics/gnome.bmp");  
    loaded = true;
  }
  </code></pre>
  
  <p><strong>File:  Living.h</strong></p>
  
  <pre><code>#include &lt;iostream&gt;  
  #include "Sprite.h"
  
  
  using namespace std;
  
  class Sprite;
  
  class Living {
  protected:
      int x,y;
      static Sprite *spriteImg; //= NULL;
      bool loaded;
  
      void reset();
  
  public:
      Living();
      ~Living();
      int getX();
      void setX(int _x);
      int getY();
      void setY(int _y);
      void virtual drawObjects() =0;
  };
  </code></pre>
  
  <p>But when I try to build it, the linker shows this error:</p>
  
  <blockquote>
    <p>Undefined reference to Living::spriteImg</p>
  </blockquote>
  
  <p>I have no idea how to fix this -- what's the problem?</p>