Compiler Crash with C++ Array

In your source file you have

int previousTurns[10];
int count = 0;

those are different from previousTurns and count members of Dice. Actually they are completely unrelated variables that just happen to have the same name. The member count on the other hand is used uninitialized here:

 previousTurns[count] = roll;

Note that in the member function it is the member count, not the one from int count = 0;. You should initalize it in the constructor, something like this:

Dice::Dice() : count(0) {}

Also note that you should call seed only once (eg in the constructor) and not each time you roll a number.

Leave a Comment