std::sort() on a vector of Class pointers
问题 I have a vector of class pointers std::vector<Square*> listSquares . I want to sort it with one of the attributes of the class as the key. This is what I'm doing bool compById(Square* a, Square* b) { return a->getId() < b->getId(); } std::sort(listSquares.begin(), listSquares.end(), compById) but the compiler says: error: no matching function for call to 'sort(std::vector::iterator, std::vector::iterator, <unresolved overloaded function type>)' what am I doing wrong here? 回答1: In order to use