title: Initializing a static pointer in C++
body: <p>I have a class with a static member that's a pointer like so :</p>
  
  <p>animation.h</p>
  
  <pre><code>class Animation
  {
  public:
      Animation();
      static QString *m;
  
  };
  </code></pre>
  
  <p>animation.cpp</p>
  
  <pre><code>#include "animation.h"
  
  QString* Animation::m = 0;
  
  Animation::Animation()
  {
  }
  </code></pre>
  
  <p>When I try to initialize that 'm' pointer from another class like so :</p>
  
  <pre><code>Animation::m = new QString("testing");
  </code></pre>
  
  <p>It works.</p>
  
  <p>But when I do it this way :</p>
  
  <pre><code>QString x("Testing");
  Animation::m = &amp;x;
  </code></pre>
  
  <p>The program crashes.</p>
  
  <p>What is wrong with this second method ?</p>
  
  <p>Also I would like to have that static pointer as private so I can make static getter and setter functions to it. The setter should use the second method as the 'x' will come in a parameter so I'm stuck.</p>
  
  <p>Thanks for any help!</p>