我正在使用一个定义接口的库:
template<class desttype>
void connect(desttype* pclass, void (desttype::*pmemfun)());
我有一个小的层次结构
class base {
void foo();
};
class derived: public base { ... };
在 的成员函数中derived
,我想调用
connect(this, &derived::foo);
但似乎它&derived::foo
实际上是一个成员函数指针base
;gcc 吐出来
error: no matching function for call to ‘connect(derived* const&, void (base::* const&)())’
我可以通过显式转换this
为来解决这个问题base *
;但是为什么编译器不能匹配调用desttype = base
(因为derived *
可以隐式转换为base *
)?
另外,为什么不是 &derived::foo
成员函数指针derived
?