c++ - Trying to remove vector pointer duplicates. Why can't I use .erase()? -


i've got vector of pointers "faction" class, stored in such way:

vector<faction *> factionptr_; 

at point, able sort vector in alphabetical order, figured use code here remove duplicates that'd show next each other:

void faction::deleteduplicatefaction(vector<faction *> &factionptr_){   (int = 0; < factionptr_.size()-1; i++){        if (factionptr_[i]->getfactionname() == factionptr_[i + 1]->getfactionname()){             cout << "it's same" << endl;              factionptr_.erase(factionptr(i));       } 

but i'm getting error @ .erase() , don't understand:

    intellisense: no instance of overloaded function "std::vector<_ty, _alloc>::erase [with _ty=faction *, _alloc=std::allocator<faction *>]" matches argument list         argument types are: (faction *)         object type is: std::vector<faction *, std::allocator<faction *>>    

now understand using iterators this, i'm not familiar them yet. not averse solution involving iterators though.

perhaps there's way?

factionptr this:

faction * faction::factionptr(int k) const{  if ((k < 0) or(k > numberoffactions())) // elementary error checking       return null;   return factionptr_[k]; // returns pointer k-th daughter 

}

wheel reinvention should discouraged. std::unique simple custom predicate followed erase.

auto pred = [](faction* a, faction* b) {                  return a->getfactionname() == b->getfactionname();              }; factionptr_.erase(std::unique(factionptr_.begin(), factionptr_.end(), pred),                   factionptr_.end()); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -