C++ 中的函数指针错误

Function Pointer Error in C++

这是我收到的错误:

error: no matching function for call to ‘pcl::ConditionalEuclideanClustering
<pcl::Normal>::setConditionFunction(bool (EuclideanPlaneSegmentation::*)(const pcl::Normal&, const pcl::Normal&, float))’ cec.setConditionFunction(&EuclideanPlaneSegmentation::customRegionGrowing; ^ note: candidate is:/segmentation/conditional_euclidean_clustering.h:125:7:
  note: void pcl::ConditionalEuclideanClustering
  <PointT>::setConditionFunction(bool (*)(const PointT&, const PointT&, float)) [with PointT = pcl::Normal] setConditionFunction (bool (*condition_function) (const PointT&, const PointT&, float)) ^ note: no known conversion for argument 1 from ‘bool (EuclideanPlaneSegmentation::*)(const
    pcl::Normal&, const pcl::Normal&, float)’ to ‘bool (*)(const pcl::Normal&, const pcl::Normal&, float)’

基本上,我有 "EuclideanPlaneSegmentation" Class,我正在尝试应用这个 pcl 教程:http://pointclouds.org/documentation/tutorials/conditional_euclidean_clustering.php

在教程中,在主函数中

cec.setConditionFunction (&customRegionGrowing);

尝试访问函数:

    bool
    customRegionGrowing (const PointTypeFull& point_a, const   PointTypeFull&     point_b, float squared_distance)
    {
    Eigen::Map<const Eigen::Vector3f> point_a_normal = point_a.normal,        point_b_normal = point_b.normal;
    if (squared_distance < 10000)
    {
    if (fabs (point_a.intensity - point_b.intensity) < 8.0f)
      return (true);
    if (fabs (point_a_normal.dot (point_b_normal)) < 0.06)
      return (true);
  }
    else
    {
    if (fabs (point_a.intensity - point_b.intensity) < 3.0f)
    return (true);
    }
    return (false);
    }
}

我的 class 中有相同的功能,我试过:

cec.setConditionFunction(&EuclideanPlaneSegmentation::customRegionGrowing);

但它不起作用。我收到我写的错误。

在我的 class 中,如果我尝试

cec.setConditionFunction (&customRegionGrowing);

我收到这个错误:

/EuclideanPlaneSegmentation.cpp:402:28: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say ‘&EuclideanPlaneSegmentation::customRegionGrowing’ [-fpermissive]
      cec.setConditionFunction(&customRegionGrowing);
                                ^
  /EuclideanPlaneSegmentation.cpp:402:65: error: no matching function for call to ‘pcl::ConditionalEuclideanClustering<pcl::Normal>::setConditionFunction(bool (EuclideanPlaneSegmentation::*)(const pcl::Normal&, const pcl::Normal&, float))’
      cec.setConditionFunction(&customRegionGrowing);

有人知道我如何解决这个问题有什么问题吗?

方法 setConditionFunction 需要一个函数,但您传递的是成员(非静态)方法。声明传递的方法 static 应该可以解决问题。

传递静态方法有效。但是如果你想在你的条件下动态重新配置参数,你可以使用

setConditionFunction(boost::bind(&regularization, this, _1, _2, _3))