我有一个向量类指针std::vector<Square*> listSquares
。我想用类的其中一个属性作为关键字进行排序。这是我在做什么std :: sort()在类指针向量上
bool compById(Square* a, Square* b)
{
return a->getId() < b->getId();
}
std::sort(listSquares.begin(), listSquares.end(), compById)
但是编译器说: 错误:没有匹配函数调用“排序(标准::矢量::迭代器,性病::矢量::迭代器,<悬而未决超载功能类型>)'
我在做什么错在这里?
如果你可以使用C++ 11,你应该做这个拉姆达:'的std ::排序(listSquares.begin(),listSquares.end(),[](方*一,广场* B ){return a-> getId()< b-> getId;})'。 – leftaroundabout 2013-05-03 20:28:39
确保你确实需要指针而不仅仅是对象。 – chris 2013-05-03 20:30:19
我无法使用C++ 11。 @chris我相信我想使用指针。 – qutab 2013-05-03 20:37:45