Alright so in Class A I have:
int* attackerDice;
int* defenderDice;
these two variables call on another class called dice. So:
attackerDice = dice.roll()
defenderDice = dice.roll()
what dice.roll does is the following:
int* Dice::roll () {
int* ran = new int[1];
srand(time(NULL));
ran[0] = rand()%6+1;
std::sort(ran,ran+1);
return ran;
}
Now the problem that I am getting is attackerDice is returning -43249211234 while defender dice is returning the right number. I assume this is because I clearly do not understand when to use * and &. Can anyone help me out?
Edit: How would I go about doing this if I wanted to have an array? Id like to have it so that I can roll X number of dice
int? That uses more memory, will be error prone, and is slower than just returning anint. Why are you sorting an array with a single element?std::sort(ran,ran+1);Huh? What's the purpose of this? You are trying to sort an array with a single element?