I'm trying call a method initialised by pointer to a method of other class, i've followed this:
but it has not worked for me.
int GetValue(int z)
return 4 * z;
int(hooky::*HookGetValue)(int) = (int(hooky::*)(int))0x0; // memory address or &y::GetValue;
hooky h; // instance
cout << h.*HookGetValue(4) << endl; // error
[Error] must use '.' or '->' to call pointer-to-member function in
'HookGetValue (...)', e.g. '(... ->* HookGetValue) (...)'
The correct syntax to invoke a member function pointer is
Update: the reason original code does not work as expected is because of operator precedence of C++: function invocation
() is having higher precedence than ptr to member
.*. Which means
will be see as