sort 排序 自定义排序算法的使用

// struct sort_by_pt
// {
// bool operator()(const std::pair<CString, AcGePoint3d> a, const std::pair<CString, AcGePoint3d> b)
// {
// return a.second.x < b.second.x;
// }
// };

// bool Compare_indexx(PtToText a, PtToText b)
// {
// double pta = a.ptx;
// double ptb = b.ptx;
// return pta.x<ptb.x;
// } 

 

std::sort(allText.begin(), allText.end(), [](const PtToText&a, const PtToText&b){return a.ptx<b.ptx; }); 

 

重载运算符

class test
{
public:
test();
~test();

private:
public:
int a;
struct qqq
{
int d;
double b;
};
qqq m_s;
int test::operator+(const test&b)
{
return a+ b.a;
}
int test::operator-(const test&b)
{
return a - b.a;
}
};

test::test()
{
}

test::~test()
{
}
int _tmain(int argc, _TCHAR* argv[])
{
test ds,da;
ds.a = 50;
da.a = 20;
int b = ds + da;
int c = ds - da;
cout << b << endl;
cout << c << endl;
return 0;
}

posted @ 2017-04-13 09:04  xzh1993  阅读(426)  评论(0)    收藏  举报