假设你有
struct A{
void f(){}
};
struct B:public A{
};
template<typename C,void (C::*f)()>
struct Call{
void operator()(C* c){
(c->*f)();
}
};
为什么
int main(){
void (B::*f)()=&B::f;
}
工作但
Call<B,&B::f> a;
没有,抱怨
could not convert template argument ‘&A::f’ to ‘void (B::*)()
?
(Call<A,&A::f>
显然有效)
以类似的方式
const void (B::*f)()=&B::f;
给
cannot convert ‘void (A::*)()’ to ‘const void (B::*)()’ in initialization