title: Error: terminate called throwing an exceptionAbort trap: 6
body: <p>I am making a hot potato game that deals with inheritance. I have a potato class, player class and umpire class. </p>
  
  <p>In calling the toss function within my umpire class I KEEP getting this same error and I can't seem to figure out why: terminate called throwing an exceptionAbort trap: 6</p>
  
  <p>I went through and found that within umpire::start(), the call to Players.at(randU)->toss(*m) in my for loop is making this error come up. But everything looks fine to me. </p>
  
  <p>Can anyone help me out? Thanks!</p>
  
  <p><strong>Umpire.cc</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include "potato.h"
  #include "player.h"
  #include "umpire.h"
  #include "PRNG.h"
  using namespace std;
  
  // Declare globally
  int gamecount=1;
  
  // GLOBAL VARIABLES
  bool first=false; // False if set has not started
  PRNG rplayer;
  
  // UMPIRE CONSTRUCTOR-------------------------------------------------------------------
  Umpire::Umpire( Player::PlayerList &amp;players ){
     Players=players;
     cout&lt;&lt;"\tMashed POTATO will go off after ";
     cout.flush();
     m=new Mashed(Players.size()-1);
     cout &lt;&lt; " tosses" &lt;&lt; endl;
     cout.flush();
     cout &lt;&lt;"\tFried POTATO will go off after 5 tosses" &lt;&lt; endl;  
     cout.flush();
     f=new Fried(5);}
  
  // UMPIRE DESTRUCTOR-------------------------------------------------------------------
  Umpire::~Umpire(){  
      delete m;
      delete f;}
  
  
  // UMPIRE START------------------------------------------------------------------------
  void Umpire::start(){
  int randU;
  int gameCount=1; // Keeps track of sets
  
  // Check if you are at the end of the list.
  if(Players.size()==1){
      // Who won?
      cout &lt;&lt; Players.at(0)-&gt;getId() &lt;&lt; "wins the Match!" &lt;&lt; endl;
      cout.flush();}
  else{
  
  // Print output for sets----------------------------------------------------------------
  // See which potato is being used in the set
  if(gameCount%2!=0){ 
      cout &lt;&lt; "Set " &lt;&lt; gameCount &lt;&lt; "-\tUser (mashed) [";
      cout.flush();}
  else{ 
      cout &lt;&lt; "Set " &lt;&lt; gameCount &lt;&lt; "-\tUser (fried) [";
      cout.flush();}
  gameCount++; // increase gamecount
  // Outputting players left in the set
  for(unsigned int i=0;i&lt;Players.size();i++){
      cout&lt;&lt;Players.at(i)-&gt;getId();}
  cout &lt;&lt;"]: ";
  cout.flush();
  
  //Start Tossing--------------------------------------------------------------------------
      randU=rplayer(Players.size()-1);
      // Output A(id) or R(id)
      if (randU%2==0){
          cout&lt;&lt;"A("&lt;&lt;randU&lt;&lt;"), ";
          cout.flush();}
      else{
          cout&lt;&lt;"R("&lt;&lt;randU&lt;&lt;"), ";
          cout.flush();}
      if(first==false){
          for(unsigned int i=0; i&lt;Players.size(); i++){
              if(Players.at(i)-&gt;getId()==Players.at(randU)-&gt;toss(*m)){
                  Players.erase(Players.begin()+i);
                  cout &lt;&lt; "Eliminated: "&lt;&lt; i &lt;&lt; endl;
                  cout.flush();}
          }
          first=true;
          f-&gt;reset();
          start();
      }
      else{
          for(unsigned int i=0; i&lt;Players.size(); i++){
              if(Players.at(i)-&gt;getId()==Players.at(randU)-&gt;toss(*f)){
                  Players.erase(Players.begin()+i);
                  cout &lt;&lt; "Eliminated: "&lt;&lt; i &lt;&lt; endl;
                  cout.flush();}
          } 
          first=false;
          m-&gt;reset();
          start();
          }
      }
  }
  </code></pre>
  
  <p><strong>Player.cc</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "player.h"
  #include "potato.h"
  #include "PRNG.h"
  using namespace std;
  
  // GLOBAL DECLARATIONS--------------------------------------------------------------------
  PRNG randP;
  
  // PLAYER CONSTRUCTOR---------------------------------------------------------------------
  Player::Player(unsigned int id, Player::PlayerList &amp;players){
      pid=id;
      Players=players;
      lrpFLAG=false;}
  
  // getId() returns the player's id--------------------------------------------------------
  unsigned int Player::getId(){
          return pid;}
  
  // RNPlayer Constructor-------------------------------------------------------------------
  RNPlayer::RNPlayer( unsigned int id, Player::PlayerList &amp;players ) : Player(id,players){}
  
  // TOSS FUNCTION--------------------------------------------------------------------------
  unsigned int RNPlayer::toss( Potato &amp;potato ){
  unsigned int randnum;
  if(potato.countdown()){ return getId(); }
      for(;;){    
          randnum=randP(Players.size()-1);
          if (randnum%2==0){
              cout&lt;&lt;"A("&lt;&lt;randnum&lt;&lt;"), ";
              cout.flush();}
          else{
              cout&lt;&lt;"R("&lt;&lt;randnum&lt;&lt;"), ";
              cout.flush();}
          // If our randomly selected player is not the current player...
          if(Players.at(randnum)-&gt;getId()!=getId()){
              break;}
      }   
  return Players.at(randnum)-&gt;toss(potato);
  }
  
  // LRPlayer Constructor-------------------------------------------------------------------
  LRPlayer::LRPlayer( unsigned int id, Player::PlayerList &amp;players ) : Player(id,players){}
  
  // TOSS FUNCTION
  unsigned int LRPlayer::toss( Potato &amp;potato ){
      unsigned int current; // current player
      // Find who our current player is
      for(unsigned int i=0; i&lt;Players.size(); i++){
          if(Players.at(i)-&gt;getId()==getId()){
              current=i;
              cout&lt;&lt;"A("&lt;&lt;i&lt;&lt;"), ";}
      }
      // if timer hasn't gone off yet...
      if(potato.countdown()!=true){
      // if this is the FIRST toss, we want to toss left
          if(lrpFLAG==false){
              if(current==0){
                  lrpFLAG=true;
                  (Players.at(Players.size()-1))-&gt;toss(potato);}
              else{
                  lrpFLAG=true;
                  (Players.at(current-1))-&gt;toss(potato);}
              }
          else{
              if(current==Players.size()-1){
                  lrpFLAG=false;
                  (Players.at(0))-&gt;toss(potato);}
              else{
                  lrpFLAG=false;
                  (Players.at(current+1))-&gt;toss(potato);}
              }
          }
      return (Players.at(current))-&gt;getId();
  }
  </code></pre>
  
  <p><strong>Main.cc</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;time.h&gt;
  #include "potato.h"
  #include "player.h"
  #include "umpire.h"
  #include "PRNG.h"
  using namespace std;
  
  int main(int argc, char *argv[] ){
      int p = 5;
      int tmp;
      unsigned int s;
      PRNG prng1;
      prng1.seed(1234567890);
      // Parse the command line arguments
      switch ( argc ) {
          case 3:
              tmp=atoi(argv[1]);
              s=atoi(argv[2]);
              prng1.seed(s);
              if(tmp&lt;2 || tmp&gt;20){
                  cout &lt;&lt; "Player must be between 2 and 20 inclusive" &lt;&lt; endl;
                      return 0;}
              else{
                  p = atoi(argv[1]);}
          }
      // Creating list of players.
      Player::PlayerList players;
      for(int i=0; i&lt;p; i++){
          if(i%2==0){
              players.push_back(new LRPlayer(i,players));}
          else{               
              players.push_back(new RNPlayer(i,players));}
          }
  
  //for (int i=0;i&lt;players.size();i++){
  //  cout &lt;&lt; "Player at " &lt;&lt; i &lt;&lt; " id: " &lt;&lt; players.at(i)-&gt;getId() &lt;&lt; endl;}
  
  // How many players?----------------------------------------------------------------------
  cout &lt;&lt; p &lt;&lt; " players in the match" &lt;&lt; endl;
  
  // Construct an UMPIRE--------------------------------------------------------------------
  Umpire u(players);
  
  // Start the game!------------------------------------------------------------------------
  u.start();
  
  }
  </code></pre>
  
  <p>Also note: PRNG.h is a class that generates a random number. so PRNG prng1; int rand=prng1(#) generates a random number between 0 and #.</p>
  
  <p><strong>ALSO:</strong>
  The problem is occurring when i call my toss function. I'm not out of range because when i try to call Players.at(randU)->getID() i don't get any errors at all. Could it be that i can't reach the toss function for that player?I'm thinking it has to do with something im pointing to or memory. I first make a PlayerList players in my main.cc and push_back players alternating between the two. But each player also takes in a list. Maybe I'm running into errors involved with this?</p>
  
  <p>Thanks! Any help is much appreciated :)</p>