Hi all,
I have a stl::vector containing pointers to objects. I need to sort this vector based on a member variable (accessible by a getter function). Can someone give me a clue as to how to go about this?
I've tried a few things - but nothing has really worked, I think mainly because every bit of information I can find on this doesn't talk about pointers...
For instance, one of the methods I tried was:
Code:
class Ccharacter {
int m_spawnOrder;
int getSpawnOrder();
public:
Ccharacter(int spawnOrder);
bool operator<(const Ccharacter& a) const;
};
Ccharacter::Ccharacter(int spawnOrder) {
m_spawnOrder = spawnOrder
}
int Ccharacter::getSpawnOrder() {
return m_spawnOrder;
}
bool Ccharacter::operator<(const Ccharacter& a) const {
return this->getSpawnOrder() < a.getSpawnOrder();
}
I have a vector like such that I need to sort:
Code:
vector <Ccharacter *> listOfCharacters;
The operator< is not getting called at all in this scenario.
Cheers,
B