原始自定义函数:
//输入:Rect a 和 Rect b
//输出:当a的面积小于b的面积时输出1
int Frame_Method::cmp_func_area(const CvRect&a,const CvRect&b)
{
}
这种方式下提示有上述错误“invalid operator<”。
修改后:
int Frame_Method::cmp_func_area(const CvRect&a,const CvRect&b)
{
}
这样就正确了;
原因:
上述程序错误原因:a>b时返回ture,ab时返回ture,其它(小于等于)都是false
VS2005,VS2008后的sort()里,用的是所谓的“ strict weak ordering”,也就是说,如果a==b,则返回的应该是false,如果返回的是true,则会出上面的错。
1、出现"Expression : invalid operator <"的写法
bool CustPredicate (int elem1, int elem2 )
{
}
2、为了解决错误,应把以上代码改写为以下两种中的任一种:
(1)
bool CustPredicate (int elem1, int elem2 )
{
}
(2)
bool CustPredicate (int elem1, int elem2 )
{
}