Supponiamo di averePassando una funzione superclasse come parametro di template non typename
struct A{
void f(){}
};
struct B:public A{
};
template<typename C,void (C::*f)()>
struct Call{
void operator()(C* c){
(c->*f)();
}
};
Perché
int main(){
void (B::*f)()=&B::f;
}
lavoro, ma
Call<B,&B::f> a;
non, lamentando
could not convert template argument ‘&A::f’ to ‘void (B::*)()
?
(Call<A,&A::f>
funziona chiaramente)
In modo simile
const void (B::*f)()=&B::f;
dà
cannot convert ‘void (A::*)()’ to ‘const void (B::*)()’ in initialization
Grande, grazie! A proposito, sai anche che const void (B :: * f)() = &B::f; non è accettato? –
@Fabio: void (B :: * const f)() = & B :: f funziona bene :). const void (B :: * f)() significa puntatore al metodo che restituisce il valore const void, quindi le firme dei metodi sono mismatch in quest'ultimo caso. – user396672
scusa, hai ragione, grazie! –