C++ CArray类及子类,使用sort()排序

 

http://www.codeguru.com/forum/archive/index.php/t-215414.html

 

这篇贴子帮了大忙。有一个回贴这样说到:

 

#include <algorithm>
...
// Note the *only* change is the template type!
CArray<unsigned char, unsigned char> MyCArray;
//...
std::sort( MyCArray.GetData(), MyCArray.GetData() + MyCArray.GetSize());

It doesn't matter whether it's a CArray of strings, ints, chars, doubles, widgets, or your own class. As long as the items are comparable using operator < (which is what std::sort uses internally), the std::sort will work.

 

当然,sort()里如果用到自定义比较函数,自己写了。。。

你可能感兴趣的:(C++)