title: Detect modification of variable at runtime in C/C++
body: <p>I am developing a library in C++ where users/programmer will extend a class <code>BaseClass</code> that has a method <code>initArray</code>. This method should be implemented by the user/programmer and it should normally initialize all elements of the array <code>m_arr</code>.</p>
  
  <p>Here is a snipplet, modified to this example:</p>
  
  <pre><code>class BaseClass {
       public:
  
       BaseClass(int n) {
           m_arr = new double[n]; 
           size = n;
       };
       virtual ~BaseClass();
  
       int size;
       double* m_arr;
  
       virtual int initArray();
  };
  </code></pre>
  
  <p>Sometimes, the user/programmer implements a <code>initArray</code> that does not initialize some elements of m_arr. What I would like is to create a function in my library that checks if <code>initArray</code> did initialize all elements of <code>m_arr</code>. This function should be called by a sanity-check rutine at <strong>runtime</strong>.</p>
  
  <p>My question: is it possible to detect changes on this array? I can only think of initializing the array with some invalid values (like NaN or Inf), call <code>initArray</code> and check that all values have changed.</p>
  
  <p>Thanks for your ideas,</p>
  
  <p>David</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>Here is an example of the client code that I am trying to detect:</p>
  
  <pre><code>// .h:
  class MyExample : public BaseClass {
       public:
       MyExample();
       virtual ~MyExample();
       virtual int initArray();
  };
  
  // .cpp:
  MyExample::MyExample() : BaseClass(3) { }
  MyExample::~MyExample() { }
  int MyExample::initArray() {
       m_arr[0] = 10;
       //m_arr[1] = 11; // let's say someone forgot this line
       m_arr[2] = 12;
       return 0;
  }
  </code></pre>
  
  <p>So, by forgetting the <code>m_arr[1]</code> this element is not initialized and could cause problems in future calculations. That's what I would like to check.</p>