私は他の人の質問を見たことがありますが、私がここで達成しようとしていることに当てはまるものは見つかりませんでした。
std::sortとaを使用してEntityManagerクラスを介してエンティティを並べ替えようとしています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);
}
次のようなエラーが多数発生します
: error: no match for call to '(compareByX) (GameEntity* const&, GameEntity* const&)'
: note: candidates are: bool compareByX::operator()(const GameEntity&, const GameEntity&)
よくわかりませんが、ENTITY_VECTORはですstd::vector<Entity *>
。これが、compareByX関数オブジェクトを使用するときに問題になる可能性があるかどうかはわかりません。
私はC++にかなり慣れていないので、どんな種類の助けも歓迎します。