vector<int> numList;
}
void Game::start(int n, int m) {
srand((unsigned) time(NULL));
for (int a = 0; a < n; a++) {
int randomNum = 1 + (rand() % m);
Game::numList.push_back(randomNum);
}
}
int Game::checkGuess(vector<int> guessList) {
vector<int> compareVector(guessList.size(), 0);
int numCorrect = 0;
//Compare guesses to random number list and update compareVector if correct
//The compareVector will ensure numbers are compared correctly if there are duplicates
for (int guessCounter = 0; guessCounter < guessList.size(); guessCounter++) {
//Loop through the list
for (int listCounter = 0; listCounter < Game::numList.size(); listCounter++) {
//check if value has been guessed or not to prevent one number counting for duplicates
if (compareVector.at(listCounter) == 0) {
if (guessList.at(guessCounter) == Game::numList.at(listCounter)) {
numCorrect++;
compareVector.at(guessCounter) = 1;
break;
}
else {
listCounter++;
}
}
}
guessCounter++;
}
//Once all values are checked, return the number correct
return numCorrect;
}
I create the class and default constructor creates the numList vector which works fine, but when I call other functions within that class, numList is again size zero after updating it in the start function. How do I get it to maintain the updated values.