I have:
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() );
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());
Default argument cannot be provided for pointers to functions.
You can use pointers to call functions and to pass functions as arguments to other functions. You cannot perform pointer arithmetic on pointers to functions. For z/OS® XL C/C++, use the __cdecl keyword to declare a pointer to a function as a C linkage.
In C, like normal data pointers (int *, char *, etc), we can have pointers to functions. Following is a simple example that shows declaration and function call using function pointer.
int foo(int); Here foo is a function that returns int and takes one argument of int type. So as a logical guy will think, by putting a * operator between int and foo(int) should create a pointer to a function i.e. int * foo(int);
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.
Default parameters aren't part of the function signature, so you can't do this directly.
However, you could define a wrapper function for create_hough_features
, or just a second overload that only takes two arguments:
void create_hough_features(const cv::Mat & image, cv::Mat & resp, FeatureParams & params) {
// blah
}
void create_hough_features(const cv::Mat & image, cv::Mat & resp) {
create_hough_features(image, resp, DefaultParams());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With