nki*_*int 1 c++ std min stdvector aabb
我不是一个c ++编码器,所以可能很容易.
我有一个Point类的向量,我想找到AABB矩形:
我已经完成了一个for循环,保存了min和max(一次为x,一次为y),并用一些ifs更新每次迭代的值.
但我确信在std或boost中有更聪明的东西.
例如我刚试过:
vector<ofPoint> points;
// ....
bool _compareX(ofPoint const &p1, ofPoint const &p2) { return p1.x > p2.x; }
bool _compareY(ofPoint const &p1, ofPoint const &p2) { return p1.y > p2.y;}
void DrawerWidget::foo()
{
cout << std::min_element(points.begin(), points.end(), &_compareX) << endl;
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个奇怪的错误,如
错误:'std :: cout << std :: min_element中没有匹配'operator <<'[与_FIter = __gnu_cxx :: __ normal_iterator >>,_Compare = bool()(const ofPoint&,const ofPoint&)](((DrawerWidget)))> - DrawerWidget :: points.std :: vector <_Tp,_Alloc> ::以_Tp = ofVec3f开头,_Alloc = std :: allocator,((DrawerWidget*)this) - > DrawerWidget :: points.std: :vector <_Tp,_Alloc> :: end with _Tp = ofVec3f,_Alloc = std :: allocator,_compareX)'
如果我将min_element放在<<上的其他地方,则会出现类似的错误
min_element将迭代器返回到最小元素,您尝试将其发送到cout.
使用:
std::cout<<*min_element()
Run Code Online (Sandbox Code Playgroud)
<<除非vector元素是cout已经有重载<<运算符的类型,否则您还需要重载.
| 归档时间: |
|
| 查看次数: |
734 次 |
| 最近记录: |