title: Address of a static variable when instance created
body: <p>I have a c++ class which has static const and static variable on it.
  During startup I initialize all the static const variables with some string values and all the static variables with zeros. </p>
  
  <p>Then I create 1st instance of that class and tried to modify the static variable alone.
  Then I create 2nd instance of the same class and tried to write some other value other than what I wrote for the 1st instance.</p>
  
  <p>Later, when I tried to access the static variable of the 1st instance, it hold the 2nd instance values. while looking into the memory location I found variable pointer address are same for both instances.</p>
  
  <p>Is it something I wrote wrongly?</p>
  
  <p>My code snippet:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;time.h&gt;
  #include &lt;stdlib.h&gt;
  
  CBase::CBase(const myStruct *myStructPtr) {
      initStruct(myStructPtr);
  }
  
  CBase::~CBase() {}
  
  void CBase::initStruct(const myStruct *myStructPtr) {
      m_myStructPtr = const_cast&lt;myStruct *&gt;(myStructPtr);
      if (m_myStructPtr) {
          uint8_t nNumDatas = (m_myStructPtr-&gt;numOfOutputs) ? (m_myStructPtr-&gt;numOfOutputs - 1) : 0;
          if (nNumDatas) {
              for (int idx = 0; idx &lt; m_myStructPtr-&gt;numOfOutputs - 1; idx++) {
                  if (m_myStructPtr-&gt;someNumber[idx])
                      m_myStructPtr-&gt;someNumber[idx] = (unsigned int)rand();
              }
          }
      }
  }
  
  void CBase::printSomeNumber() {
  
  if (m_myStructPtr) {
      uint8_t nNumDatas = (m_myStructPtr-&gt;numOfOutputs) ? (m_myStructPtr-&gt;numOfOutputs - 1) : 0;
      if (nNumDatas) {
          for (int idx = 0; idx &lt; m_myStructPtr-&gt;numOfOutputs - 1; idx++) {
              printf("\n printing : name %s, print number : 0x%x", m_myStructPtr-&gt;someName[idx],m_myStructPtr-&gt;someNumber[idx]);
          }
      }
  }
  }
  
  const char * CDerived::scm_acsomeName[] = { "INIT", "REQ", NULL };
  unsigned int CDerived::sm_aunsomeNumber[] = { 0, 0xDEADBEEF };
  
  const myStruct CDerived::myDerivedStruct = {
      3, scm_acsomeName, sm_aunsomeNumber
  };
  
  int main()
  {
      CBase *FirstDerived = new CDerived();
      CBase *SecondDerived = new CDerived();
  
  FirstDerived-&gt;printSomeNumber();
  SecondDerived-&gt;printSomeNumber();
  while (1);
  return 0;
  }
  </code></pre>
  
  <p>My header file:</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  struct myStruct {
      uint8_t numOfOutputs;
      const char **someName;
      unsigned int *someNumber;
  };
  
  class CBase
  {
  public:
      CBase(const myStruct *myStructPtr);
      virtual ~CBase();
      void printSomeNumber();
  private:
      CBase(const CBase&amp;);
      void initStruct(const myStruct *myStructPtr);
  
  protected:
      const myStruct* m_myStructPtr;
  };
  
  class CDerived : public CBase {
  private:
      static const myStruct myDerivedStruct;
      static const char *scm_acsomeName[];
      static unsigned int sm_aunsomeNumber[];
  
  public:
      CDerived() : CBase(&amp;myDerivedStruct) {}
      virtual ~CDerived() {}
  };
  </code></pre>
  
  <p>console print message:</p>
  
  <pre><code>printing : name INIT, print number : 0x0
   printing : name REQ, print number : 0x4823
   printing : name INIT, print number : 0x0
   printing : name REQ, print number : 0x4823
  </code></pre>