Сейчас я беру уроки по C ++, C # и Java, поэтому я думаю, что некоторые вещи перепутаны.У меня проблемы с установкой значения bool для объектов, и что странно, это то, что значения int, которые я устанавливаю для других объектов, сохраняют изменения.Я изначально настраиваю его в функции внутри Main.После выхода из функции и возврата в основную функцию значения верны.На следующей итерации первый объект все еще имеет новые значения, но второй объект вернулся к исходным значениям.
Это цикл в моей основной функции
while (true) {
Player player = playerQueue.front();
//stores the current cell the player is on
int cellNumber = gameBoard.findCell(player.getCellNum())->nodeNumber;
Cell currCell = gameBoard.getCellObject(cellNumber);
//check cell property
if (currCell.getCanBuy() == false){
//pay the property owner
} else {
DisplayPlayerInfo(player, currCell);
}
}
Здесь у игрока есть возможность купить ячейку.Функции для объекта Player изменяются правильно, но объект Cell (prop) изменяется, но затем возвращается после итерации цикла while.
void DisplayPlayerInfo(Player &player, Cell &prop) {
if (input == "y" || input == "Y") {
if (player.getCurrency() >= prop.getPrice()) {
//buy property
prop.setCanBuy(false);
player.subtractCurrency(prop.getPrice());
player.addProperty(prop);
}
}
else if (input == "n" || input == "N"){
return;
} else {
//return error
}
}
Это мои установщики для объекта Player и Cell соответственно
//Player setter
void Player::setPlayerName(std::string name) { pName = name; }
void Player::setQueuePos(int q) { queuePos = q; }
void Player::setCellNum(int num) { cellNum = num; }
void Player::addCurrency(int amt) { currency += amt; }
void Player::subtractCurrency(int amt) { currency -= amt; }
//Cell setter
void Cell::setCanBuy(bool val) { canBuy = val; }
edit: Сокращенный код до того, что, я думаю, имеет отношение к вопросу.