title: C++ static const variable and destruction
body: <p>I have encountered a strange behavior with a simple C++ class.</p>
  
  <p>classA.h</p>
  
  <pre><code>class A
  {
  public:
    A();
    ~A();
    static const std::string CONST_STR;
  };
  </code></pre>
  
  <p>classA.cpp</p>
  
  <pre><code>#include "classA.h"
  #include &lt;cassert&gt;
  
  const std::string A::CONST_STR("some text");
  
  A::A()
  {
    assert(!CONST_STR.empty()); //OK
  }
  
  A::~A()
  {
    assert(!CONST_STR.empty()); //fails
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;memory&gt;  
  #include &lt;classA.h&gt;  
  
  std::auto_ptr&lt;A&gt; g_aStuff; 
  
  int main() 
  { 
    //do something ... 
    g_aStuff = std::auto_ptr&lt;A&gt;(new A()); 
    //do something ... 
    return 0; 
  }
  </code></pre>
  
  <p>I'd expect access violations or anything similar, but I'd never expect that the content of the static const string could change. Does anyone here have a good explanation what happens in that code?</p>
  
  <p>thanks,
  Norbert</p>