views:

17

answers:

0

Given the following member function overload to take various functors

class Foo { 
public: 
     void bar(boost::function<void(int)> func); 
     void bar(boost::function<void(float)> func); 
     void bar(boost::function<void(const std::vector<float>&)> func); 
}

and the function

void baz(float f) { std::cout << "float :" << f << std::endl; }

then why does taking the plain function pointer of baz

Foo foo; 
foo.bar(&baz);

yield this error:

error: call of overloaded ‘bar(void (*)(float))’ is ambiguous 
note: candidates are: void Foo::bar(boost::function<void(int)>) 
note: void Foo::bar(boost::function<void(float)>) 
note: void Foo::bar(boost::function<void(const std::vector<float, std::allocator<float> >&)>)

How to resolve this ambiguity ?