首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用lambda替换std::bind

如何使用lambda替换std::bind
EN

Stack Overflow用户
提问于 2021-05-14 22:47:23
回答 1查看 68关注 0票数 0
代码语言:javascript
复制
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);

我像这样写代码:

代码语言:javascript
复制
 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);
};

func merge_lanes使用它:

代码语言:javascript
复制
merge_lanes(prob_thresh_list_, detected_lanes.lanes, tracked_lanes.lanes,
            result.lanes, next_track_id, detection_score_threshold_,
            lane_distance_calculator); 

错误:

代码语言:javascript
复制
 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);

我该怎么解决它呢?这让我困惑了很长时间。

EN

回答 1

Stack Overflow用户

发布于 2021-05-15 01:55:37

你已经很接近了。试着这样做:

代码语言:javascript
复制
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);
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67536296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档