我必须将函数传递到指针。为此,我使用boost :: function。捕获指针的函数对于不同的签名来说是过载的。例如:指针功能
void Foo(boost::function<int()>) { ... }
void Foo(boost::function<float()>) { ... }
void Foo(boost::function<double()>) { ... }
现在我想通过一些类方法的指针有:
class test
{
public:
float toCall() { };
};
class Wrapper
{
Wrapper() {
test obj;
Foo(boost::bind(&test::toCall, this));
}
};
error: no matching function for call to ‘Foo(boost::_bi::bind_t<float, boost::_mfi::mf0<float, test>, boost::_bi::list1<boost::_bi::value<Wrapper*> > >)’
note: candidates are: Foo(boost::function<float()>&)
对于助推功能,场景甚至比这更邪恶。它就像'template struct A {template A(U); };'现在,* *看起来不能解决我的问题xD请注意,如果只有一个函数,你可以转换。难点是*比较*两个这样的转换序列。在boost :: function的情况下,这是完全不可能的,在你的情况下,它可能是可能的,但它对于over-res来说太复杂了。 –
2010-08-30 23:42:50
@Johannes Schaub:你说得对。我的例子说明了一个完全不同的问题:歧义而不是“不可解决”:) – AnT 2010-08-30 23:47:36