方法一、以类为比较器
struct classCompare
{
bool operator()(const int& lhs, const int& rhs)
{
return lhs < rhs ;
}
};
int main(void)
{
set<int, classCompare> aSet ;
system("pause") ;
return 0 ;
}
方法二、以指针函数为比较器
bool fncmp(int lhs, int rhs)
{
return lhs < rhs ;
}
int main(void)
{
bool(*fn_pt)(int, int) = fncmp ;
set<int, bool(*)(int, int)> aSet(fn_pt) ;
system("pause") ;
return 0 ;
}
方法三、在类定义里面重载operator算子(略)
采用第一种吧。