I get error unresolved overloaded function type in

2019-05-31 08:21发布

问题:

Why would piece of code like this:

boost::bind (SomeFunc<float>, function arguments go here);

produce this error:

no matching function for call to bind(<unresolved overloaded function type>

THanks

回答1:

It could be that your function SomeFunc<float> is overloaded, in which case boost::bind cannot deal with this. You have to implement a manual solution, see here for more details:



回答2:

You need to use a static_cast to tell the compiler which overload to pick if it's ambiguous, e.g.:

#include <boost/bind.hpp>

void foo(int) {}
void foo(double) {}

int main() {
  boost::bind(static_cast<void(*)(int)>(&foo), _1);
}

Sometimes "unresolved overloaded function type" can mean "none of the overloads are viable" in which case you need to figure out why it can't use any and fix that.



标签: c++ boost