This is what I try to achieve:
class MyClass
{
public:
template<typename T>
void whenEntering( const std::string& strState,
T& t,
void T::(*pMemberFunction)(void)) /// compilation fails here
{
t.(*pMemberFunction)(); // this line is only an example
}
}
It’s for a kind of callback system for reacting to some events I receive.
However Visual 2010 gives me the following compilation error:
error C2589: '(' : illegal token on right side of '::'
I may be wrong with the pointer-to-member syntax… but I am also afraid that I may not define a template this way… do you have any idea ?
You want
void (T::*pMemberFunction)(void)The other issue is probably just a typo in your example usage, but calling the member function uses
.*as a single operator; you can’t have a(in-between them, or even whitespace. I’m guessing that’s a typo because it’s almost the correct way to deal with the weird operator precedence that pointer-to-member operators have: