Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 对struct的向量进行排序会导致VisualStudio抛出一个带有“;“调试断言失败”;_C++_Sorting_Stl_Opencv - Fatal编程技术网

C++ 对struct的向量进行排序会导致VisualStudio抛出一个带有“;“调试断言失败”;

C++ 对struct的向量进行排序会导致VisualStudio抛出一个带有“;“调试断言失败”;,c++,sorting,stl,opencv,C++,Sorting,Stl,Opencv,我有一个简单的矩形结构,有x,y,width和height,我认为使用向量很容易,但结果是非常混乱 这就是我的主要观点: vector<CvRect> v; v.push_back(cvRect(50,0,50, 50)); v.push_back(cvRect(150, 0, 50,50)); v.push_back(cvRect(100, 0, 50,50)); sort(v.begin(), v.end(), rectangleCmpByPosition); 定义如下: st

我有一个简单的矩形结构,有x,y,width和height,我认为使用向量很容易,但结果是非常混乱

这就是我的主要观点:

vector<CvRect> v;
v.push_back(cvRect(50,0,50, 50));
v.push_back(cvRect(150, 0, 50,50));
v.push_back(cvRect(100, 0, 50,50));
sort(v.begin(), v.end(), rectangleCmpByPosition);
定义如下:

static int rectangleCmpByPosition(const CvRect& a, const CvRect &b){
    if (a.y != b.y){
        return a.y - b.y;
    }else{
        return a.x - b.x;
    }
}
VisualStudio会向我抛出此错误消息


我花了整个下午的时间在谷歌上搜索我做错了什么,但我找不到原因。请帮助。

您的比较器不正确。如果
a
小于
b
,则比较器需要返回
bool
true
,否则返回
false
。它需要提供一个。您的比较器不正确。如果
a
小于
b
,则比较器需要返回
bool
true
,否则返回
false
。它需要提供一个。

谢谢您的帮助。我知道这很愚蠢。谢谢你的帮助。我知道这是很愚蠢的事情。
static int rectangleCmpByPosition(const CvRect& a, const CvRect &b){
    if (a.y != b.y){
        return a.y - b.y;
    }else{
        return a.x - b.x;
    }
}