Declaring functors for comparison ??
        Posted  
        
            by Mr.Gando
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mr.Gando
        
        
        
        Published on 2009-11-19T18:33:15Z
        Indexed on 
            2010/04/10
            18:23 UTC
        
        
        Read the original article
        Hit count: 471
        
Hello, I have seen other people questions but found none that applied to what I'm trying to achieve here.
I'm trying to sort Entities via my EntityManager class using std::sort and a std::vector<Entity *>
/*Entity.h*/
class Entity
{
public:
 float x,y;
};
struct compareByX{
 bool operator()(const GameEntity &a, const GameEntity &b)
 {
  return (a.x < b.x);
 }
};   
/*Class EntityManager that uses  Entitiy*/
typedef std::vector<Entity *> ENTITY_VECTOR; //Entity reference vector
class EntityManager: public Entity
{
private:
 ENTITY_VECTOR managedEntities;
public:
 void sortEntitiesX();
};
void EntityManager::sortEntitiesX()
{
 /*perform sorting of the entitiesList by their X value*/
 compareByX comparer;
 std::sort(entityList.begin(), entityList.end(), comparer);
}
I'm getting a dozen of errors like
: error: no match for call to '(compareByX) (GameEntity* const&, GameEntity* const&)'
: note: candidates are: bool compareByX::operator()(const GameEntity&, const GameEntity&)
I'm not sure but ENTITY_VECTOR is std::vector<Entity *> , and I don't know if that could be the problem when using the compareByX functor ?
I'm pretty new to C++, so any kind of help is welcome.
© Stack Overflow or respective owner