Error when testing the value in 2Dim array
Posted on 2003-02-27
In a class header file for Dohickey I have a private class data member declared as:
I get a runtime error that says “unhandled exception in….Access Violation” when I try to fill the array through the use of a public member function in my implementation file (.cpp) holding all my class member functions:
void Dohicky::setArray(int d1, int d2)
if (Array[d1][d2] = = 0)
I had initialized Array in my constructor by saying :
Array = NULL;
Could this have caused the error...perhaps? Would it have made a difference if I had initialize Array by saying :
for(int y = 0; y < num; y++)
for(int x = 0; x < num; x++)
Array[x][y] = 0;
I’m obviously not too good with Arrays and pointers, but I’m getting there (albeit slowly). My program fails only during runtime. Is it possible to know why this might be happening from what I've provided here in this post? If needed, let me know whether I have not given enough information to allow an answer.
Thanks to anyone who can point me in the right direction.