You won't need to understand this if you use a
macro for member-function-pointer calls. Oh yea, please
use a macro in this case. And did I
mention that you should use a macro in this
case??!?
But if you really want to avoid the macro, sigh, groan, okay, here it is: use
.* when the left-hand argument is a reference to an object, and
->* when it is a pointer to an object.
For example:
class Fred { ... };
typedef int (Fred::*FredMemFn)(int i, double d); // use a typedef!!! please!!!
void sample(Fred x, Fred& y, Fred* z, FredMemFn func)
{
x.*func(42, 3.14);
y.*func(42, 3.14);
z->*func(42, 3.14);
}
BUT please consider
using a macro
instead:
void sample(Fred x, Fred& y, Fred* z, FredMemFn func)
{
CALL_MEMBER_FN(x,func)(42, 3.14);
CALL_MEMBER_FN(y,func)(42, 3.14);
CALL_MEMBER_FN(*z,func)(42, 3.14);
}
As discussed
earlier, real-world
invocations are often much more complicated than the simple ones here, so
using a macro will typically improve your code's writability and readability.