如何:具有默认值的c ++函数指针 [英] Howto: c++ Function Pointer with default values
本文介绍了如何:具有默认值的c ++函数指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
typedef void (*RespExtractor) (const cv::Mat & image, cv::Mat & resp);
virtual void predict_image(const cv::Mat & src,
cv::Mat & img_detect,cv::Size patch_size,
RespExtractor );
void create_hough_features(const cv::Mat & image, cv::Mat & resp, FeatureParams & params = FeatureParams() );
我如何定义RespExtractor以接受具有默认参数的函数,例如我可以调用:
How would i define the RespExtractor to accept a function with default parameters, such i can call:
predict_image(im_in,im_out,create_hough_features);
我尝试了以下操作,但没有成功:
I tried following, with no succes:
typedef void (*RespExtractor) (const cv::Mat & image, cv::Mat & resp,FeatureParams params, FeatureParams());
推荐答案
函数指针本身不能具有默认值.您要么必须通过函数指针将调用包装在确实具有默认参数的函数中(这甚至可以是包装函数指针并具有带有默认参数的operator()
的小类),或者具有不同的函数指针针对您的函数的不同重载.
Function pointers themselves can't have default values. You'll either have to wrap the call via the function pointer in a function that does have default parameters (this could even be a small class that wraps the function pointer and has an operator()
with default paremeters), or have different function pointers for the different overloads of your functions.
这篇关于如何:具有默认值的c ++函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文