What you're trying to do is conditionally supported behavior in C++11,
and illegal in earlier versions, in both cases. You can't reliably
convert a pointer to a function (member or otherwise) to a void*
.
(I've worked on systems where a pointer to a function was 32 bits, but a
void*
only 16.)
In practice, most compilers will (illegally, in pre-C++11) ignore the
error for non-member functions. Posix requires that function
pointers and data pointers be compatible, and they are under Windows as
well. (Today: only of the systems where they weren't for me was an
early Unix.) As for pointers to members: a pointer to a static member
has a type compatible to a pointer to a function (and so will work in
practice, if the compiler allows it), but a pointer to a non-static
member has a completely different type, usually with a different size,
and a different representation. About the only way you can reliably
output one is as a series of byte values: put the address in a properly
typed variable, take the address of that variable, convert it to
unsigned char const*
, then use "%02x"
to output each byte.
But the real question is why you want to do this. There is nothing that
you can reliably do with the value you output, regardlessly of how you
output it.