// 仿函数排序类对象
#include <iostream>
#include <vector>
#include <algorithm>
struct A {
A(int m) : x(m) {}
bool operator<(const A& a)const {
return this->x < a.x;
}
int x;
};
int main() {
A a1(5);
A a2(2);
std::vector<A> vec;
vec.push_back(a1);
vec.push_back(a2);
std::sort(vec.begin(), vec.end());
for(int i = 0;i < vec.size();++i) {
std::cout << vec[i].x << std::endl;
}
return 0;
}
仿函数排序类对象
最新推荐文章于 2023-12-29 17:34:28 发布