I keep getting this error when I run my code. I'm not sure why I keep getting this error because I call delete on two objects which I have allocated using the new operator.
I have tried running it in Xcode and I get a thread 1: signal SIGABRT error.
PokerV2.cpp
int main() {
bool game_flag = true;
Poker_Game game1;
game1.initialise_game();
game1.game_run();
while (game_flag) {
char input = 'a';
game_flag = false;
game1.game_run(game1.get_current_players());
std::cout << "Press 'y' to continue";
std::cin >> input;
if (input == 'y') {
game_flag = true;
}
}
}
poker_game_class.hpp
void Poker_Game::game_run() {
int lowest = 10;
int num = 0;
// Create the deck and table dynamically
Deck *deck = new Deck();
Table *table = new Table(_player_num);
deck->deal_cards(table->get_all_players(), _player_num, *table);
for (int i = 0; i < 4; i++) {
table->set_game_flag(i);
table->set_highest_bet(0);
for (int z = 0; z < table->get_player_num(); z++) {
table->players_turn(z);
}
}
for (int i = 0; i < table->get_player_num(); i++) {
if (table->get_player(i).calculate_score(*table) < lowest) {
num = i;
}
}
std::cout << "The winner is player: " << num << "\n";
std::cout << "The winner has won: £" << table->get_pot() << "\n";
//Add total pot to players cash
float current_balance = table->get_player(num).get_balance();
float balance_after_win = current_balance + table->get_pot();
table->get_player(num).set_balance(balance_after_win);
std::cout << "Winners balance: £" << table->get_player(num).get_balance();
this->Current_players = table->get_all_players();
delete deck;
delete table;
}
The error occurs in the game_run function just when the deck and table are deleted.
Below is the linked GitHub repository
delete deckdoesn't work afterdeck = new Deck(), then allocating the object on the stack isn't going to fix whatever's actually wrong. - jamesdlin