I'm seeing some big bad error messages whilst trying to erase a string from a vector. I'm trying to use the erase-remove idiom but it's not working. Here are some snippets to show my predicament.
team.players.erase( remove(team.players.begin(), team.players.end(),
player_name), team.players.end());
team.players is declared in this struct:
struct team
{
string name;
player captain;
vector<player> players;
};
The vector team.players is populated dynamically as the program runs, and at some point a user has the option to remove a player via a menu.
if (select_option == PRINT_TEAM) print_team(team);
if (select_option == CHANGE_TEAM_NAME) change_team_name(team);
if (select_option == CHANGE_CAPTAIN) change_captain(team);
if (select_option == ADD_PLAYER) add_player(team);
if (select_option == REMOVE_PLAYER) remove_player(team);
if (select_option == QUIT) exit(0);
However I'm getting these errors as I tried to compile my program (clang++), long before the function is called. Here are the errors:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:865:22: error: invalid operands to binary expression ('player' and 'const std::__1::basic_string<char>')
if (*__first == __value_)
~~~~~~~~ ^ ~~~~~~~~
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:2125:22: note:
in instantiation of function template specialization
'std::__1::find<std::__1::__wrap_iter<player *>, std::__1::basic_string<char> >'
requested here
__first = _VSTD::find(__first, __last, __value_);
^
program2.cpp:172:25: note: in instantiation of function template specialization
'std::__1::remove<std::__1::__wrap_iter<player *>, std::__1::basic_string<char>
>' requested here
team.players.erase( remove(team.players.begin(), team.players.end(),
^
2 errors generated.
Any idea how I can fix this?
Aucun commentaire:
Enregistrer un commentaire