How do I achieve the following overloaded method call
class Foo {
void bind(const int,boost::function<int (void)> f);
void bind(const int,boost::function<std::string (void)> f);
void bind(const int,boost::function<double (void)> f);
};
First attempt
SomeClass c;
Foo f;
f.bind(1,boost::bind(&SomeClass::getint,ref(c));
f.bind(1,boost::bind(&SomeClass::getstring,ref(c)));
f.bind(1,boost::bind(&SomeClass::getdouble,ref(c)));
Then I found a possible answer so tried this:-
f.bind(static_cast<void (Foo::*)(int,boost::function<int(void)>)>(1,boost::bind(&SomeClass::getint)));
which looks ugly but might work?
but gives and error
error C2440: 'static_cast' : cannot convert from 'boost::_bi::bind_t<R,F,L>' to 'void (__cdecl Foo::* )(int,boost::function<Signature>)'
Any ideas I can make this overloading work. I suspect type erasure is occuring but the compiler obviously recognises the overloaded methods since Foo.cpp compiles fine