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"类,我正在尝试应用此 pcl 教程:http://pointclouds.org/documentation/tutorials/conditional_euclidean_clustering.php
Basically, I have "EuclideanPlaneSegmentation" Class and I am trying to apply this pcl tutorial: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);
}
}
我在课堂上也有同样的功能,我试过了:
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);
我收到此错误:
/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?
推荐答案
setConditionFunction
方法需要一个函数,但您传递的是成员(非静态)方法.声明传递的方法 static
应该可以解决问题.
The method setConditionFunction
expects a function but you are passing a member (non-static) method. Declaring the passed method static
should solve the problem.
这篇关于C++中的函数指针错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!