问题
Here is the error I am getting:
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)’
Basically, I have "EuclideanPlaneSegmentation" Class and I am trying to apply this pcl tutorial:http://pointclouds.org/documentation/tutorials/conditional_euclidean_clustering.php
In tutorial, in main function
cec.setConditionFunction (&customRegionGrowing);
tries to get to the function:
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);
}
}
I have the same function in my class and I tried:
cec.setConditionFunction(&EuclideanPlaneSegmentation::customRegionGrowing);
but it does not work. I receive the error I wrote.
In my class, if I try
cec.setConditionFunction (&customRegionGrowing);
I get this error:
/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);
Does anyone have any idea what is wrong with how I can solve that problem?
回答1:
The method setConditionFunction
expects a function but you are passing a member (non-static) method. Declaring the passed method static
should solve the problem.
回答2:
Passing the static method works. But in case you want to dynamically reconfigure parameters in your condition you can use
setConditionFunction(boost::bind(®ularization, this, _1, _2, _3))
来源:https://stackoverflow.com/questions/29564245/function-pointer-error-in-c