Why can't member functions be used as template arguments? For example, I want to do this:
struct Foo {
void Bar() {
}
};
template <typename TOwner, void(&func)()>
void Call(TOwner *p) {
p->func();
}
int main() {
Foo a;
Call<Foo, Foo::Bar>(&a);
return 0;
}
I know that this can be done using member pointers; OK, this is cool enough most of the time, but I'm just wondering why pointers should be used.
I do not see the ambiguity of the interpretation of "p-> func ()" above. Why does the standard forbid us to use member functions as template arguments? Even static member functions are not allowed according to my compiler (VC ++ 2013). Does anyone know the reason? Or is there a way to do the same without losing any performance due to pointer dereferencing?
Thank.