Detect modification of variable at runtime in C/C++
- by YuppieNetworking
Hello,
I am developing a library in C++ where users/programmer will extend a class BaseClass that has a method initArray. This method should be implemented by the user/programmer and it should normally initialize all elements of the array m_arr.
Here is a snipplet, modified to this example:
class BaseClass {
public:
BaseClass(int n) {
m_arr = new double[n];
size = n;
};
virtual ~BaseClass();
int size;
double* m_arr;
virtual int initArray();
};
Sometimes, the user/programmer implements a initArray that does not initialize some elements of m_arr. What I would like is to create a function in my library that checks if initArray did initialize all elements of m_arr. This function should be called by a sanity-check rutine at runtime.
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 initArray and check that all values have changed.
Thanks for your ideas,
David