access violation reading location c++

Two things here:

You are not calling “initializeArray()” at all. So when you are trying to access the array there is nothing there. I would recommend calling it in the constructor. Like this:

Numbers(int num)
{
    number = num;
    hundred = "hundred";
    thousand = "thousand";
    one = new string[SIZE1];
    ten = new string[SIZE2];
    initializeArray();
}

Second, is what the guys above said. You have an incorrect value for the size of your array since you are trying to assign 19 values to an array of size 18. Just to be really sure lets make the size bigger than we expect and you can adjust later:

const int SIZE1 = 20;
const int SIZE2 = 20;

Additionally, See your determine()? instead of using a for loop why don’t you go:

string name = one[number];

EDIT: Wow there was another thing I missed…you have declared your array pointer variable twice and so it’s actually going out of scope thinking you want to make some local versions. Look at my adjusted implementation of your constructor above again. See how I’ve removed the “String *” from before the variable names.

Leave a Comment