This post answered my original question: how can I can I template on a member function?
The answer has the code:
struct Foo {
void Bar() { // do something
}
};
template <typename TOwner, void(TOwner::*func)()>
void Call(TOwner *p) {
(p->*func)();
}
int main() {
Foo a;
Call<Foo, &Foo::Bar>(&a);
return 0;
}
I am trying to accomplish the same thing with shared pointers. I found that this does NOT work:
template <typename TOwner, void(TOwner::*func)()>
void Call(std::shared_ptr<TOwner> p) {
(p->*func)();
}
However, this works
template <typename TOwner, void(TOwner::*func)()>
void Call(std::shared_ptr<TOwner> p) {
(p.get()->*func)();
}
Is there a better way to accomplish this?