Описание тега member-function-pointers
A pointer to a member function of a C++ class.
In C++ a member function pointer is a special pointer type that refers to a specific member function of a class.
A member function pointer mfp
can be declared as:
Ret (Class::* mfp )( Arg0, Arg1 );
This declares mfp
as a pointer to a member function of the class Class
, and as a member function which returns Ret
and takes two arguments of types Arg0
and Arg1
.
The address of a member function is taken using the &
operator, qualifying the function name with the class name, e.g. mfp = &Class::func;
A member function pointer may not be represented as a simple address in memory and for some implementations sizeof(&X::f) != sizeof(void*)
. As a result, pointers to members cannot be converted to void*
like other pointers.
The C++ FAQ has a section on member function pointers.