How do I call a pointer-to-member-function?

p->pfn is a pointer of pointer-to-member-function type. In order to call a function through such a pointer you need to use either operator ->* or operator .* and supply an object of type C as the left operand. You didn’t.

I don’t know which object of type C is supposed to be used here – only you know that – but in your example it could be *this. In that case the call might look as follows

(this->*p->pfn)(val)

In order to make it look a bit less convoluted, you can introduce an intermediate variable

PFN pfn = p->pfn;
(this->*pfn)(val);

Leave a Comment