【发布时间】:2014-04-14 13:42:20
【问题描述】:
请考虑类A,以及函数对象A_less。 A_less 比较两个A 指针,取决于A::getvalue() 的结果。
class A {
int getvalue(const string &Parameter);
};
struct A_less : public binary_function<A *, A *, bool> {
A_less(const string &P) : Parameter(P) { }
bool operator()(const A *lhs, const A *rhs) const {
return A->getvalue(Parameter) < rhs->getvalue(Parameter);
}
string Parameter;
}
如何根据Parameter 的特定(运行时)值声明/创建A 指针的排序容器(集合、priority_queues ......),按A_less 排序?
【问题讨论】:
标签: c++ templates stl containers sorted