【发布时间】:2018-10-27 17:21:30
【问题描述】:
我在构建代码时遇到以下错误:
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()
);
}
我想这是一个简单的错误,但我现在已经超过一个小时找不到它;)。这只是一个小例子。
【问题讨论】:
-
在一个完全不相关的注释中,这些函数似乎没有任何意义是类的成员。
标签: c++ algorithm c++11 lambda remove-if