0

The huge error:

BlackJack.cpp: In member function âvoid BlackJack::leaveGame(const std::vector<int>&)â:
BlackJack.cpp:342:35: error: no matching function for call to âstd::vector<Player*>::erase(std::vector<Player*>::const_iterator&)â
BlackJack.cpp:342:35: note: candidates are:
In file included from /usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/vector:70:0,
                 from /usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/random.h:34,
                 from /usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/random:50,
                 from /usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_algo.h:67,
                 from /usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/algorithm:63,
                 from BlackJack.cpp:8:
/usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/vector.tcc:135:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator) [with _Tp = Player*; _Alloc = std::allocator<Player*>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<Player**, std::vector<Player*> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = Player**]
/usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/vector.tcc:135:5: note:   no known conversion for argument 1 from âstd::vector<Player*>::const_iterator {aka __gnu_cxx::__normal_iterator<Player* const*, std::vector<Player*> >}â to âstd::vector<Player*>::iterator {aka __gnu_cxx::__normal_iterator<Player**, std::vector<Player*> >}â
/usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/vector.tcc:147:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::iterator) [with _Tp = Player*; _Alloc = std::allocator<Player*>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<Player**, std::vector<Player*> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = Player**]
/usr/local/gcc4.7/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/vector.tcc:147:5: note:   candidate expects 2 arguments, 1 provided

The relevant functions :

static const vector<Player*>::const_iterator findPlayer(
        const vector<Player*>& players, int id) {///const
        vector<Player*>::const_iterator found
        = find_if(begin(players), end(players), [id] (Player* player) {
            return player->getId() == id;
        });
       return found;
    }

void BlackJack::leaveGame(const vector<int>& players){
        if(allPlayersIn(this->players_pool, players)){
            for(vector<int>::const_iterator cur_id = players.begin();
                    cur_id != players.end(); ++cur_id){
                vector<Player *>::const_iterator found =
                        findPlayer(this->_players_in, *cur_id);
                if(found != end(this->_players_in)){////end
                    this->_players_in.erase(found);
                    this->_players_in_count--;
                }
            }
        } else {
            PlayerDoesNotExistException();
        }
    }

Does anybody see why this happens ? As I know gcc++11 does support this issue. If I remove all the "const" the compiler doesn't shout.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
KittyT2016
  • 195
  • 9

0 Answers0