在自定义对象中使用accumulate
Usage of accumulate with a custom object
我正在使用c++的opencv库,我正试图计算vector<Point2f> difference
Point类的x属性是float
float pointSumX(Point2f pt1,Point2f pt2)
{
return (pt1.x + pt2.x);
}
我如上所述定义了函数,并从如下所示的accumulate调用它。但是会抛出错误
float avgMotionX = accumulate(difference.begin(),difference.end(),0,pointSumX);
错误是:
错误:无法将' __init '从' int '转换为' cv::Point_ ' __init = __binary_op(__init, *__first);
注意:我使用c++ 11
float pointSumX(Point2f pt1, Point2f pt2)
应该float pointSumX(float lhs, const Point2f& rhs)
{
return lhs + rhs.x;
}
作为lhs
为累加器。
还要注意,你应该把它叫做
std::accumulate(difference.begin(), difference.end(), 0.f, pointSumX); // 0.f instead of 0
返回float
而不是int
。
相关文章:
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- C++自定义比较函数
- 如何比较自定义类的std::变体
- std::设置自定义比较器
- 如何正确实现和访问运算符的各种自定义枚举器
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 自定义先决条件对移动分配运算符有效吗
- 使用VS Code和CMake Tools运行自定义命令
- 如何创建从Maya(或类似程序)到虚幻引擎的自定义数据导出插件
- std::ranges::elements_view,用于自定义类似元组的数据
- 跟随整数索引列表的自定义类迭代器
- 参数化自定义CMake工具链
- 使用自定义比较函数使用std::sort()对矢量字符串进行排序时出现问题
- 如何在自定义类中启用'auto loops'?
- 使用QJsEngine在Qt中注册自定义类型
- Qt自定义QPush按钮未显示在布局上
- 自定义对象的dlib序列化在gcc中失败
- 自定义创建QFuture
- 在自定义对象中使用accumulate