2

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

user1486293
  • 79
  • 1
  • 2
  • 5
  • 3
    @user1486293 - that doesn't stop you from creating a small, but real example that shows the problem, see for example the code I showed in my answer: you can reduce your problem to something that sort of size too – Flexo Jul 03 '12 at 06:55
  • possible duplicate of ["No matching function for call to bind" while using websocketpp](http://stackoverflow.com/questions/10734236/no-matching-function-for-call-to-bind-while-using-websocketpp) – Drew Noakes Nov 04 '14 at 17:37

2 Answers2

9

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:

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
3

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.

Flexo
  • 87,323
  • 22
  • 191
  • 272
  • And what if foo is template function? – user1486293 Jul 03 '12 at 06:55
  • @user1486293 - same thing with `static_cast` applies if it's ambiguous. Be careful it's not actually complaining that none of the versions of `foo` are viable instead. – Flexo Jul 03 '12 at 07:00