I want to make a template class whose constructor takes an object pointer and a pointer to one of the object's methods. The code below doesn't compile. What's the right syntax?
template <class Obj, typename Method>
class Foo
{
public:
Foo(Obj *obj, Method method)
:mObj(obj), mMethod(method)
{}
void callMethod()
{
mObj->mMethod();
}
private:
Obj* mObj;
Method* mMethod;
};
class Bar
{
public:
void method() {}
};
I get this error on the Foo constructor:
error C2440: 'initializing': cannot convert
from 'void (__thiscall Bar::* )(void)'
to 'void (__thiscall Bar::* *)(void)'