I have a vector of pointers to baseball players as indicated below
along with an iterator to traverse through the vectorCode:vector<BaseballPlayer*> team; // stores information regarding a team
The purpose of this function is to store the different class objects into the vector which will later be used to print a player's informationCode:vector<'NOT SURE WHAT TO DEFINE THIS AS'>::iterator Trav_Team; // iterator to traverse through a team
When I create a routine to traverse through the team vector to print out the player information, if they are either a pitcher or hitter, it doesn't work, because the iterator is only of a certain type. How can I get the iterator access both the Pitcher and Hitter classes? Or if there is another method I'm not aware of.Code:void PlayerDatabase::load_team(ifstream &playerINPUT) { Pitcher * ptrPitcher; Hitter * ptrHitter; int pos; cout <<"Initializing team count = 0\n" << endl; char player_Position; // player's position on the team // while there is still input, continuing reading the file // and incrementing team count until EOF occurs while(playerINPUT >> player_Position) { /* check to see if the player is a pitcher or hitter */ if(player_Position == 'P') { ptrPitcher = new Pitcher; ptrPitcher->load_player(playerINPUT); team.push_back(reinterpret_cast<BaseballPlayer*>(ptrPitcher)); //stores the Pitcher's information (object) into the team vector } else if(player_Position == 'H') { ptrHitter = new Hitter; ptrHitter->load_player(playerINPUT); team.push_back(reinterpret_cast<BaseballPlayer*>(ptrHitter)); //stores the Hitter's information (object) into the team vector } team_count++; //increment total members on team and positioning cout <<"Loading member " << team_count << endl; }//end of while loop }




Reply With Quote