Hello, I'm not exactly sure if this should be going in the beginner section or not, but I still feel like I beginner so I put it here. Anyways, I'm writing a fighting simulation-esque program where a tournament is being run. I initialized the objects and am putting them into a queue. Putting them into the queue originally goes fine, and when I pop them out it works fine as well. But, I want to push the winner back into the queue, and this is where I'm having difficulty. It runs through the 1st fight fine, but when I try to push the winner back in the program crashes, and it says there is a segmentation fault. So I'm looking for a little bit of direction in where to go from here.
do
{
//Creatures *c1; //was trying with this, but it didn't help
//c1 = player1.front();
//Creatures *c2;
//c2 = player2.front();
int first = firstAttack();//determines who attacks first
if(first == 0)//Player 1 attacks first
{
combat(player1.front(), player2.front());//battle loop function
}
else //Player 2 attacks first
{
combat(player2.front(), player1.front());//battle loop function
}
if(c1->getWinRound() == true)
{
player1.push(player1.front());//was using c1
defeated.push_back(player2.front());//was using c2
player1.pop();
player2.pop();
}
else
{
player2.push(player2.front());//was using c2
defeated.push_back(player1.front());//was using c1
player1.pop();
player2.pop();
}
}while(!player1.empty() || !player2.empty());
The Creature class is an abstract parent class, if that makes a difference, so the original objects created are dynamic objects. And defeated is a vector, and that seems to work fine. Also, in this program I'm supposed to use 2 different containers which is why I'm using both a queue and a vector. But anyways, any help would be appreciated, thank you.
Wow, I feel really dumb for not even trying that, I've been sitting here for a few hours researching around trying to figure out what to do. But doing that fixed my problem. I had it as || because there are 2 teams and there could be a case where 1 team has like 2 characters left and the other has none, so in my mind I thought it needed to be or. But actually thinking about that does make more sense. Anyways, thank you so much!