
Hello everybody! I ran into a very weird problem with boost::bind and boost::function. I am using boost 1.33.1 with a g++ 4.0.3 on a Ubuntu dapper system. The code which does not compile is: boost::function< double(double) > pFunc = boost::bind(std::pow, _1, -3); While this code fragment does: double f(double k, double p) { return std::pow(double(k), p); } boost::function< double(std::size_t) > pFunc = boost::bind(f, _1, -3); Ok, I got a solution, but may someone enlighten me what is wrong with the first version? The error message from g++ is correlFunc.cpp: In function 'int main(int, char**)': correlFunc.cpp:184: error: no matching function for call to 'bind(<unknown type>, boost::arg<1>&, double)' Thanks in advance! Greetings, Sebastian Weber

Sebastian Weber
Hello everybody!
I ran into a very weird problem with boost::bind and boost::function. I am using boost 1.33.1 with a g++ 4.0.3 on a Ubuntu dapper system. The code which does not compile is:
boost::function< double(double) > pFunc = boost::bind(std::pow, _1, -3); ... You have to specify which overloaded version of std::pow() you'd like to use:
boost::function<double(double)> pFunc = boost::bind<double, double(&)(double, double)>(std::pow, _1, -3); In this example placeholder's presence doesn't matter. Simplified version w/o placeholder: boost::function<double(void)> pFunc = boost::bind<double, double(&)(double, double)>(std::pow, 0.0, 0.0); requires explicit template parameter too, regardless of the fact that both arguments can be deduced as doubles and so, only one overloaded version is the best match. This can be illustrated by simpler example: template <typename F> void foo(F f) {} foo(std::pow); // ERROR, should be "foo<double(&)(double, double)>(std::pow);" or other overloads HTH, Andriy Tylychko, telia@vichnavich.com
participants (2)
-
Andriy Tylychko (mail.ru)
-
Sebastian Weber