- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在构建代码时遇到以下错误:
Error C2064: term does not evaluate to a function taking 1 argument
我阅读了有关此错误的其他帖子,并在我的 lambda 函数中添加了关键字 this
,但我仍然遇到相同的错误。
我正在尝试使用 C++ lambda 函数 (std::remove_if
) 在另一个类成员函数中使用一个类成员函数。
class LineSegments
{
public:
LineSegments();
float getClockwiseAngle0to180(const float& dx1, const float& dx2, const float& dy1, const float& dy2);
void eliminateParallelLineSegments(std::vector<cv::Vec4f>& lines);
~LineSegments();
};
// Constructors
LineSegments::LineSegments() {}
// Destructors
LineSegments::~LineSegments() {}
float LineSegments::getClockwiseAngle0to180(const float& dx1, const float& dx2, const float& dy1, const float& dy2) {
float dot = dx1 * dx2 + dy1 * dy2;
float det = dx1 * dy2 - dy1 * dx2;
float angle = -atan2(det, dot);
angle = angle * (180 / CV_PI);
if (angle < 0) {
angle = angle + 360;
}
if (angle >= 180) {
angle = angle - 180;
}
return angle;
}
void LineSegments::eliminateParallelLineSegments(std::vector<cv::Vec4f>& lines)
{
lines.erase(remove_if(lines.begin() + 1, lines.end(), [this](const Vec4f& left_line, const Vec4f& right_line)
{
return (abs((getClockwiseAngle0to180(0, left_line[2] - left_line[0], 1, left_line[3] - left_line[1]) - getClockwiseAngle0to180(0, right_line[2] - right_line[0], 1, right_line[3] - right_line[1]))) < 2);
})
, lines.end()
);
}
我想这是一个简单的错误,但我现在一个多小时都找不到它 ;)。这只是一个最小的例子。
最佳答案
问题出在您的 std::remove_if()
的谓词上,它应该是一元谓词。 (一元谓词只是采用单个参数并返回 bool 值的函数)。
看这个:http://en.cppreference.com/w/cpp/algorithm/remove
Parameters of
std::remove_if()
first, last : Forward iterators to the initial and final positions in a sequence of move-assignable elements. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
pred : Unary function that accepts an element in the range as argument, and returns a value convertible to bool. The value returned indicates whether the element is to be removed (if true, it is removed). The function shall not modify its argument. This can either be a function pointer or a function object.
[this] (const Vec4f &left_line, const Vec4f &right_line)
{
return (abs((getClockwiseAngle0to180(0, left_line[2] - left_line[0], 1, left_line[3] - left_line[1]) - getClockwiseAngle0to180(0, right_line[2] - right_line[0], 1, right_line[3] - right_line[1]))) < 2);
})
在这里,在您的 lambda 函数 中,您试图传递两个参数(即 const Vec4f &left_line
和 const Vec4f &right_line
),这是不可能。它应该是一元谓词。
"I read the other posts concerning this error and added the keyword
this
inside my lambda function but I am still getting the same error."
与当前对象无关。因此,这里不需要使用this
。您还可以在使用此类对象的 vector 时定义一个独立的函数。或者换句话说,您可以将 getClockwiseAngle0to180()
定义为非成员函数。
可能的解决方案如下。
auto left_line = Vec4f[1]; // as per your first element of your vector(Vec4f) that you want as lhs
lines.erase(std::remove_if(lines.begin() + 1, lines.end(),
[&] (Vec4f& right_line)->bool
{
auto temp = abs((getClockwiseAngle0to180(0, left_line[2] - left_line[0], 1, left_line[3] - left_line[1]) -
getClockwiseAngle0to180(0, right_line[2] - right_line[0], 1, right_line[3] - right_line[1]));
left_line = right_line; // now your left_line = right_line
return temp < 2 ;
}), lines.end());
PS:没有测试过。
关于c++ - 错误 C2064 : term does not evaluate to a function taking 1 argument - Lambda function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50391467/
例如,如果我的程序名称是 test.c 然后对于以下运行命令,argc = 2 而不是 4。 $test abc pqr* *xyz* 最佳答案 尝试运行: $ echo abc pqr* *xyz*
我正在尝试使用一个容器来显示TextField,但是该容器不喜欢我的操作顺序。这是我的代码: Widget build(BuildContext context) { return Scaffol
我有以下代码: class MetricGoogleGateway extends AMetricGateway{ constructor(id, name, token) {
我像这样调用下面的对象方法。 new Cout( elem1 ).load( 'body' ) new COut( elem1 ).display( 'email' ) 我一次只使用一个实例。因为我一
我正在尝试使用 C++11 中的可变参数函数模板,并通过如下代码了解了基本思想: void helper() { std::cout void helper( T&& arg ) {
在学习 ExtJS 4 时,我发现在定义一个新类时,在 initComponent 中方法可以使用 this.callParent(arguments) 调用父类的构造函数. 我想知道这个 argum
使用 XCode 9,Beta 3。Swift 4。 statsView.createButton("Button name") { [weak self] Void in //stuff st
以下代码将打印1: (function (arguments) { console.log(arguments); }(1, 2)); 实际上,arguments 对象已被覆盖。是否可以恢复函
/** * @param $name * @return Response * @Route ("/afficheN/{name}",name="afficheN") */ public fu
我习惯使用Scala scopt用于命令行选项解析。您可以选择参数是否为 .required()通过调用刚刚显示的函数。 如何定义仅在定义了另一个参数时才需要的参数? 例如,我有一个标志 --writ
所以这是我的代码: def is_valid_move(board, column): '''Returns True if and only if there is an o
我试图在这里运行此代码: threads = [threading.Thread(name='ThreadNumber{}'.format(n),target=SB, args(shoe_type,m
在静态类型函数编程语言(例如 Standard ML、F#、OCaml 和 Haskell)中,编写函数时通常将参数彼此分开,并通过空格与函数名称分开: let add a b = a + b
function validateArguments(args) { if(args.length 2) { throw new RangeError("Invalid amo
我正在使用 Django 1.5 并尝试将参数传递到我的 URL。当我使用前两个参数时,下面的代码工作正常,使用第三个参数时我收到错误。我已经引用了新的 Django 1.5 更新中的 url 用法,
我刚刚开始使用 ember js 并且多次被这个功能绊倒 有人可以简要介绍一下 this._super() 的使用,并解释 ...arguments 的重要性 谢谢 最佳答案 每当您覆盖类/函数(例如
这个问题在这里已经有了答案: How to fix an "Argument passed to call that takes no arguments" error? (2 个答案) 关闭 3
我正在创建一个简单的登录注册应用程序。但是我遇到了错误,我不知道如何解决,请帮忙!这是我的代码: // // ViewController.swift // CHLogbook-Applicati
我是 Swift 的初学者。我尝试创建一个表示 Meal 的简单类。 它有一些属性和一个返回可选的构造函数 但是当我尝试测试它或在任何地方实例化它时,我得到的只是一个错误。似乎无法弄清楚发生了什么。
我有一个在特殊环境下运行其他程序的系统程序: cset shield -e PROGRAM .现在要运行一个 java 程序,我输入了 cset shield -e java PROGRAM ,但这不
我是一名优秀的程序员,十分优秀!