How do you declare an extern "C" function pointer
You can try including cmath
instead, and using static_cast<double(*)(double)>(std::log)
(cast necessary to resolve to the double
overload).
Otherwise, you will limit your function to extern C
functions. This would work like
extern "C" typedef double (*ExtCFuncPtr)(double);
double foo(double num, ExtCFuncPtr func) {
return 65.4;
}
Another way is to make foo
a functor
struct foo {
typedef double result_type;
template<typename FuncPtr>
double operator()(double num, FuncPtr f) const {
return 65.4;
}
};
Then you can pass foo()
to boost::bind
, and because it's templated, it will accept any linkage. It will also work with function objects, not only with function pointers.
Try using a typedef:
extern "C" {
typedef double (*CDoubleFunc)(double);
}
double foo(double num, CDoubleFunc func) {
return 65.4;
}