实例代码:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <unordered_set>
#include <functional>
#include <queue>
using namespace std;
namespace _nmsp1
{
class A
{
public:
bool operator()(int i, int j)
{
return i > j;
}
};
void func()
{
vector<int> myvector = { 50, 15, 80, 30, 46 };
A mya;
sort(myvector.begin(), myvector.end(), mya);
for (auto iter = myvector.begin(); iter != myvector.end(); ++iter)
{
cout << *iter << endl;
}
return;
}
}
namespace _nmsp2
{
class A
{
public:
bool operator()(int i, int j)
{
return i > j;
}
};
void func()
{
vector<int> myvector = { 50, 15, 80, 30, 46 };
sort(myvector.begin(), myvector.end(), less<int>());
for (auto iter = myvector.begin(); iter != myvector.end(); ++iter)
{
cout << *iter << endl;
}
}
}
int main()
{
_nmsp2::func();
return 1;
}