|
|
有没有人遇到过无法用std::list指针排序的问题。如果有谁能成功修改并编译这段代码的,请赐教!
因为要存储的单元都是多态的,所以只能用指针来做模版参数
class Unit
{
public:
virtual int getID();
};
// class UnitB: public Unit {......}
class UnitA:public Unit
{
//......
};
std::list<Unit*> lstUnits;
typedef Unit* UnitPtr;
bool UnitCompare(const UnitPtr& a, const UnitPtr& b){return a->getID()<b->getID();}
//......insertions
lstUnits.sort(UnitCompare); //error C2664: 'void __thiscall std::list<struct Unit *,class std::allocator<struct Unit *> >::sort(struct std::greater<struct Unit *>)' : cannot convert parameter 1 from 'UnitCompare' to 'struct std::greater<struct Unit *>'
No constructor could take the source type, or constructor overload resolution was ambiguous |
|