次のオーバーロードされたメソッド呼び出しを実現するにはどうすればよいですか
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);
};
最初の試み
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)));
次に、可能な答えを見つけたので、これを試しました:-
f.bind(static_cast<void (Foo::*)(int,boost::function<int(void)>)>(1,boost::bind(&SomeClass::getint)));
見た目は悪いですが、うまくいくでしょうか?
しかし、与えるとエラー
error C2440: 'static_cast' : cannot convert from 'boost::_bi::bind_t<R,F,L>' to 'void (__cdecl Foo::* )(int,boost::function<Signature>)'
この過負荷を機能させることができるアイデア。型消去が発生していると思われますが、Foo.cpp は正常にコンパイルされるため、コンパイラはオーバーロードされたメソッドを明らかに認識します。