如何使用lambda替换std::bind


auto dis_calculator =
std::bind(&LaneTrackerImpl::calc_lane_distance, this,
std::placeholders::_1, std::placeholders::_2, false, 0.0f,
std::placeholders::_3, std::placeholders::_4,
std::placeholders::_5, std::placeholders::_6);

我写的代码是这样的:

auto lane_distance_calculator = [this](const Lane &lane1, const Lane &lane2,
bool disable_lane_start_distance_affection,
bool disable_lane_end_distance_affection,
DistanceMethod method, bool is_matching_phase)
{
this->calc_lane_distance(
lane1, lane2, false, 0.0f,
disable_lane_start_distance_affection,
disable_lane_end_distance_affection,
method, is_matching_phase);
};

函数merge_lanes使用它:

merge_lanes(prob_thresh_list_, detected_lanes.lanes, tracked_lanes.lanes,
result.lanes, next_track_id, detection_score_threshold_,
lane_distance_calculator); 

错误:

error: no matching function for call to ‘{anonymous}::LaneTrackerImpl::merge_lanes(std::vector<float, std::allocator<float> >&, std::vector<perception::Lane>&, std::vector<perception::Lane>&, std::vector<perception::Lane>&, size_t&, float&, {anonymous}::LaneTrackerImpl::merge(perception::LanePrediction&, perception::LanePrediction&, size_t)::<lambda(const perception::Lane&, const perception::Lane&, bool, bool, {anonymous}::LaneTrackerImpl::DistanceMethod, bool)>&)’
lane_distance_calculator);

我该如何解决?它使我困惑了很长一段时间。

你很接近。试试这个:

auto dis_calculator = [this](const Lane &lane1, const Lane &lane2,
bool disable_lane_start_distance_affection,
bool disable_lane_end_distance_affection,
DistanceMethod method, bool is_matching_phase)
{
this->calc_lane_distance(
lane1, lane2, false, 0.0f,
disable_lane_start_distance_affection,
disable_lane_end_distance_affection,
method, is_matching_phase);
};

最新更新