I have two classes, one called Handler
and one called Dice
. In my Handler
class i have a private variable called Dice **dices
and a public function called rollDices
. And in my Dice
class i have a function called toss that will randomize a number 1-6. The problem is that when the function rollDices
is calling the function toss I get EXT_BAD_ACCESS
in toss
function. Does anyone know why, and have a solution for it?
My Handler.cpp:
void Handler::rollDices(){
Dice **allDices = new Dice*[this->nrOfDices];
this->dices = allDices;
dices[nrOfDices]= new Dice(nrOfDices);
int count =1;
for (int i = 0; i < this->nrOfDices; i++)
{
allDices[i]->toss();
cout << "Dice "<< count << ": " << allDices[i]->getValue() << endl;
count ++;
}
}
My Dice.cpp:
void Dice::toss(){
this->value = rand()%this->nrOfSides+1; //Value is a private int in Dice class
}
If you need more code i can post it, just tell me!